I have a web page that creates a list of contacts and their email addresses. You have two options for the mailto link, (1) open it in the current window or (2) open it in a new tab/window.
I see potential drawbacks from both sides:
- For web mail clients (e.g. gmail) option 1 is not ideal because it hijacks the window then, and the user must navigate back to the application in some fashion
- For desktop mail clients, the first option is not ideal because now you have a blank window/tab left open
Is there anyway to "detect" if the opened webpage has content and close it if not?
Based on this link:
Detecting web-based mail client vs local mail client for a mailto link
I tried the following to get the body:
const windowRef = window.open(`mailto:${email}`, '_blank')
const body = windowRef.document.body
The problem I was running into was that the body of each document was empty: <body></body>
I assume this was because it didn't have enough time to load the page, so I attempted to setTimeout but then I got a Blocked a frame with origin "myhostman" from accessing a cross-origin frame.
Any ideas on a way to support both web and desktop mail clients without the drawbacks listed above?