Open the href mailto link in new tab / window

后端 未结 8 779
臣服心动
臣服心动 2020-12-05 09:56

I have an image which when click, I want to link to a mailto:

 
        

        
相关标签:
8条回答
  • 2020-12-05 10:24

    There is a cheap html-hack to this problem.....

    The link on one page...

    <a href="/mailto.html" target="_blank">Mail</a>
    

    On mailto.html....

    <meta HTTP-EQUIV="REFRESH" content="0; url=mailto:who@website.com">
    
    If nothing pops up click.....<a href="mailto:who@website.com">Mail!</a>
    

    _blank opens a new tab/window and the metatag does the rest. link as fallback offcourse.

    0 讨论(0)
  • 2020-12-05 10:26

    Have you tried 'middle-click' ( "Open in new tab" ) ? It works for me

    (http://forums.mozillazine.org/viewtopic.php?f=7&t=1842595)

    although it seems particularly strange to ask user to Middle click

    Anyway I've found a pseudo solution that seems to work in FF 25/ Chrome 35

    1.- Set up your link something like this:

    <a href="javascript:void()"
     class="mailToLink" 
    data-mail="mailaddr@domain.com">mailaddr@domain.com </a>
    

    2.- Using javascript ( with jquery in the example) setup an onlclick event like:

        $('.mailToLink').on('click', function(){
            mailto=$(this).data('mail');
            w=window.open('','_blank','',true);
            w.location.href='mailto:'+mailto;
            w.focus();
        });
    

    This opens a blank new window/tab and later changes its location, so the mail protocol handler is unable toto act until the new window is already opened

    Not tested with Local mail client ( Outlook et al.)

    0 讨论(0)
  • 2020-12-05 10:35

    mailto calls the users default email client. It does not open a window or tab in any instance. If you want to use a window or tab you need to configure a form and allow the form to open in your window/tab. Of course, you'll have to configure the form to send mail with whatever method is available on your server.

    0 讨论(0)
  • 2020-12-05 10:38

    this information is outdated, now it is possible to do so i believe, since gmail and others now work via browser links. there is however the problem that you would only want it to open in a new tab if NOT opening in a system mail client, and open in a new tab if it is a webmail client, otherwise for example Outlook users see a blank tab appear, which is disorienting, especially since they are Outlook users.

    0 讨论(0)
  • 2020-12-05 10:39

    You don't need Javascript/Jquery for this. A standard link works (except Firefox v30+ due to a bug, see below).

    <a href="mailto:example@example.com" target="_blank">
    

    As of Firefox 30, does not work in Firefox due to a bug. It opens in the same tab AND replaces history so hitting back will not bring you back to the page where the mailto: link was.

    0 讨论(0)
  • 2020-12-05 10:42

    This answer is based on this answer Open the href mailto link in new tab / window.

    Right now, new browsers support some web mail interfaces (Like Gmail, Yahoo Mail, AoL, etc.).

    So we can simply open a new window (Support older browser, new browsers just will open a new tab) and add a fallback (In case of non-javascript user) using preventDefault and default link redirection.

    http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-cancelation

    https://developer.mozilla.org/es/docs/DOM/event.preventDefault

    https://developer.mozilla.org/en-US/docs/Web/API/Window.open

    Like so:

    <a onClick="javascript:window.open('mailto:mail@domain.com', 'mail');event.preventDefault()" href="mailto:mail@domain.com">Send a e-mail</a>

    http://jsfiddle.net/cNUNP/

    Credit to https://stackoverflow.com/a/9880404/1107020

    Guess that's all.

    Greetings, Marcos.

    0 讨论(0)
提交回复
热议问题