Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript mailto using window open

Tags:

javascript

I currently have a form set up with 5 radio options. I have a switch statement depending on the option you pick and that determines where the email is going to go.

Inside my switch, I have this piece of code.

window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody); 

It all works fine when it opens up my email client with all of the content however it also opens a blank page in the browser.

Is there another way to achieve this or prevent a blank window from opening but still make it as if you clicked on the href:mailto ?

like image 599
SBB Avatar asked Jan 30 '14 16:01

SBB


People also ask

How do I open a mail window in HTML?

You may use window. location. href = "mailto:[email protected]"; but this will work only if in browser setting Gmail opening is not setted, etc.

How do you use mailto in JavaScript?

Use the code below and add mailto functionality to any element using JavaScript. Copy var email = document. createElement("a"); email. href = "mailto:[email protected]"; email.

Why is mailto not working?

If mailto links don't open for you the way they should, a quick look at the system or browser settings should do the job. In Windows, head to Settings -> Apps -> Default apps. Scroll down and pick “Choose default apps by protocol” from the menu. For 'Mailto', choose the client of your choice.

What is the mailto link?

Email (mailto) links are used for linking directly to an email address, which will automatically launch an email browser when the link is clicked.


1 Answers

Instead of:

window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody); 

You can try:

location.href = "mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody; 
like image 158
Rodrigo5244 Avatar answered Sep 21 '22 20:09

Rodrigo5244