Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent mailto event from opening a new tab in browser

I am using a mailto: filled in JavaScript to send information throughout my web application, but everytime a user presses the Send button, it opens a new tab in the browser before opening the mailing application (Outlook, Gmail, etc).

Is there any way to prevent the blank tab from opening?


Edit: This issue is encountered in all following major browsers : Internet Explorer, Firefox and Google Chrome.

I am using window.open() to send emails, is there any known alternatives?

Here is how I send the email:

var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message; var win = window.open(mailto_link,'emailWindow'); 

I don't want to use window.location.href since I am displaying a message after the user sent the email.

like image 860
Jeff Noel Avatar asked Nov 19 '12 16:11

Jeff Noel


1 Answers

Thank you for the edit. There is indeed an alternative:

window.location.href = "mailto:[email protected]"; alert("Thank you!"); 

I don't want to use window.location.href since I am displaying a message after the user sent the email.

I did not really get this one. You are not leaving the website when using mailto: with window.location.href

like image 166
AmShaegar Avatar answered Oct 08 '22 09:10

AmShaegar