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 ?
You may use window. location. href = "mailto:[email protected]"; but this will work only if in browser setting Gmail opening is not setted, etc.
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.
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.
Email (mailto) links are used for linking directly to an email address, which will automatically launch an email browser when the link is clicked.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With