mailto link not working within a frame chrome (over https)
Asked Answered
R

7

27

I have a mailto link on a page. It works as expected when the page is loaded by itself.

However when the page is loaded via a frameset in Chrome nothing happens. With the developer tools loaded the error "[blocked] The page at https://mysite.com ran insecure content from mailto:..." is displayed.

How can I fix/workaround this?

Retroaction answered 7/10, 2013 at 21:0 Comment(2)
It looks like Dale has filed a bug with Chrome: code.google.com/p/chromium/issues/…Whimsicality
tel: links are affected too. Same solutions apply.Jiva
B
29

I also had this issue recently with an iframe. Using the top frame worked and should be compatible with all major browsers.

window.top.location = 'mailto:...';
Bokbokhara answered 12/11, 2013 at 18:59 Comment(5)
So you would have to write a javascript onclick (or something similar) to handle this mailto: link? I'm just looking for a the syntax for this solution.Wyeth
Yes, using "top" is the trick, but you can do it with HTML alone! <a target="_top" href="mailto:...">email</a>Whimsicality
Hi, I just came across this issue today.. and this solution works. however I just want to understand why it works? why setting the target to _top works? Does the browser not care to check for security if an anchor link is outside of an iFrame?Empathy
tried all combinations, this is the only one that worked for me in Chrome without having to open a blank windowPollak
@Whimsicality I am using a component that accepts an onClick, for me this is the only thing that worked. I can't use HTML for this one, i.e. it needs to be triggered programmatically through callback.Pollak
W
33

Yes, using "top" is the trick, but you can do it with HTML alone!

<a target="_top" href="mailto:...">email</a>
Whimsicality answered 22/4, 2014 at 16:7 Comment(7)
This is excellent. It allows mailto links to now work within an iframe using the Chrome browser. Thank you very much!!!Diarmit
I had a problem making mailto: links in a Facebook frame. This worked!Individuality
Never knew what "_top" was for, until now (shame on me). This solves some problems I had on a range of Android phones as well. Thanks!Fluorescence
Also fixes mailto: links when using URL Frame masking to forward a URL!Thurston
I would recommend using _blank instead of _top. If the user set a web-based email client as the default email tool, the email client page will replace the parent page with _top.Osmunda
@Adamy, Yes the iframe case is a good point. However, you'll want to use _self, not _blank. _blank will cause a new blank untitled tab to open. _top will trigger window.onbeforeunload to fire. If the top frame is observing window.onbeforeunload, you may see a warning like "Are you sure you want to leave this page?" (If you click yes, the mailto will still work fine.) See this plunker embed.plnkr.co/12QvXVVbSKjuVT1cjrc0/preview Note that plunker's preview window is in an iframe and if you click edit then run you'll see an onbeforeunload warning message for the _top example.Whimsicality
@Whimsicality Thanks for your advice. However in my case as I set up gmail (in Chrome) as my default email application, _self doesn't do anything when I clicked on the link.Osmunda
B
29

I also had this issue recently with an iframe. Using the top frame worked and should be compatible with all major browsers.

window.top.location = 'mailto:...';
Bokbokhara answered 12/11, 2013 at 18:59 Comment(5)
So you would have to write a javascript onclick (or something similar) to handle this mailto: link? I'm just looking for a the syntax for this solution.Wyeth
Yes, using "top" is the trick, but you can do it with HTML alone! <a target="_top" href="mailto:...">email</a>Whimsicality
Hi, I just came across this issue today.. and this solution works. however I just want to understand why it works? why setting the target to _top works? Does the browser not care to check for security if an anchor link is outside of an iFrame?Empathy
tried all combinations, this is the only one that worked for me in Chrome without having to open a blank windowPollak
@Whimsicality I am using a component that accepts an onClick, for me this is the only thing that worked. I can't use HTML for this one, i.e. it needs to be triggered programmatically through callback.Pollak
B
6

Here is the solution I ended up with: Tested with Chrome, Firefox, IE6, IE7, IE8, IE9, IE10, IE11, Safari

$("a[href^='mailto:']").on("click",function() {
    window.top.location = $(this).prop("href");
    return false;
});
Beery answered 18/11, 2013 at 16:21 Comment(2)
Strangely I couldn't get that to work - it seemed to die inside jquery somewhere (we're using V 1.6.1 still). But as soon as I used the click method instead it worked well. Good stuff.Retroaction
Yes, on is the new click for newer versions of jQuery.Beery
G
3

This will also work, and won't close the window with Facebook.

<a href="mailto:..." target="_blank">...</a>

or

$("a[href^='mailto:']").attr('target','_blank');
Groundmass answered 13/8, 2014 at 12:12 Comment(0)
F
3

add target="_top" or "_blank" or "_parent"

<a target="_top" href="mailto:[email protected]">email1</a>

<a target="_top" href="mailto:[email protected]">email2</a>

Fuji answered 12/9, 2014 at 3:37 Comment(0)
V
1

Possibly because your parent frameset is https, but Chrome now seems to treat the mailto link as insecure.

I just came across a similar issue when triggering a mailto link via

window.location = 'mailto:...'

Changing it to this worked around it.

window.open( 'mailto:...')
Vlada answered 8/10, 2013 at 8:44 Comment(3)
It sounds like its a bug then? In which case I should file a bug report?Retroaction
OK, your workaround does open a new email, but it also opens a new, blank, tab/window which isn't desirable. I've opened a bug report with google.Retroaction
Yup it does. We had to script it immediately closing, which is still a bit rubbish.Vlada
O
0

This is my workaround until Chrome bug is fixed:

$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); 

if($.browser.chrome){
     myWindow=window.open("mailto:"+eml+"?subject="+msb,'','width=50,height=50');
     myWindow.close();
} else {
    window.location.href = "mailto:"+eml+"?subject="+msb;
}

For Chrome, make instance with window.open() method and close that instance immediately. Small window will "blink" for a short period but will do the job. It is "dirty" solution but as much as Chrome's bug.

For other browsers window.location() method can be used.

Obliging answered 22/10, 2013 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.