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?
<div>
and not a block<a>
? Are you able to change the markup/CSS? – Jeopardous<a>
just like you can style a<div>
, providing you display it as a block – Jeopardous