I'm creating a custom button on my webpage which actually is a <div>
, I want to trigger a mailto when the button is clicked. What is the best way out?
I've tried calling a javascript function using-onClick that looks like this -
function foo(){ window.open("mailto:[email protected]"); }
But that opens a new tab in Chrome first, and then asks for the relevant app to send out the email. This experience is different from what we generally get when we simply do a <a href=mailto:.....>
in HTML.
I can also create a new document element in the JS function, and simulate a click like this -
function sendEmail() { var mail = 'mailto:[email protected]'; var a = document.createElement('a'); a.href = mail; a.click(); };
But i'm not too sure if that's the right way! Anyone has a better solution?
If you're not using a rich text module or a CTA, you can create a mailto link manually instead. Highlight the text you want to link, then click the Link to dropdown menu and select URL. In the Link URL field, enter mailto:[email protected], then replace [email protected] with the recipient's email address.
In HTML you can specify a mailto: address in the <form> element's [action] attribute. What this will do is allow the user's email client to create an email prepopulated with the fields in the <form> .
The Mailto format does not support HTML code emails. Outlook was used at 2003, but to become compliant with the mailto: standard they removed that functionality. But you can Use %0D%0A for a line break in HTML body.
HTML <a> tag provides you option to specify an email address to send an email. While using <a> tag as an email tag, you will use mailto: email address along with href attribute. Following is the syntax of using mailto instead of using http. This code will generate the following link which you can use to send email.
Try this, and tell me if works. (If not, I will delete answer.)
<script> function sendEmail() { window.location = "mailto:[email protected]"; } </script> <div onclick="sendEmail();">Send e-mail</div>
It is possible to pass the parameters subject and body, but I think that it is not possible to format the text:
<a href='mailto:[email protected]?subject=Me&body=Hello!'>EMAIL</a>
Extremely late to the party I know, but what about combining these answers into something simpler and more practical:
<div class="button" onclick="location.href='mailto:[email protected]';">Send E-Mail</div>
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