28

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?

2

7 Answers 7

34

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

<a target="_top" href="mailto:...">email</a>
7
  • This is excellent. It allows mailto links to now work within an iframe using the Chrome browser. Thank you very much!!!
    – rrudland
    Commented Oct 1, 2014 at 19:58
  • I had a problem making mailto: links in a Facebook frame. This worked! Commented Dec 2, 2014 at 16:10
  • 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!
    – Jurgen
    Commented Feb 11, 2015 at 11:02
  • Also fixes mailto: links when using URL Frame masking to forward a URL!
    – Warpling
    Commented May 14, 2015 at 6:37
  • 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.
    – Adamy
    Commented Jun 7, 2015 at 22:12
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:...';
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.
    – Chris
    Commented Nov 20, 2013 at 15:21
  • 9
    Yes, using "top" is the trick, but you can do it with HTML alone! <a target="_top" href="mailto:...">email</a>
    – kendsnyder
    Commented Apr 22, 2014 at 16:07
  • 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?
    – jmesolomon
    Commented Jun 21, 2019 at 3:09
  • tried all combinations, this is the only one that worked for me in Chrome without having to open a blank window
    – Antoni4
    Commented Aug 28, 2019 at 15:27
  • @kendsnyder 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.
    – Antoni4
    Commented Aug 28, 2019 at 15:30
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;
});
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.
    – Dale K
    Commented Nov 18, 2013 at 21:49
  • Yes, on is the new click for newer versions of jQuery.
    – Davin
    Commented Nov 19, 2013 at 22:37
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>

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');
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:...')
3
  • It sounds like its a bug then? In which case I should file a bug report?
    – Dale K
    Commented Oct 8, 2013 at 19:21
  • 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.
    – Dale K
    Commented Oct 11, 2013 at 4:36
  • 1
    Yup it does. We had to script it immediately closing, which is still a bit rubbish.
    – Hugh
    Commented Oct 11, 2013 at 8:28
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.