Mailto link open in new tab - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Mailto link open in new tab

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function SendEmail() {//from   w w w .j av  a 2 s .  c  om
  const windowRef = window.open(`mailto:email@address.com`, '_blank');
  windowRef.focus();
  setTimeout(function(){
     if(!windowRef.document.hasFocus()) {
       windowRef.close();
    }
  }, 500);
}

      </script> 
   </head> 
   <body> 
      <a href="javascript:void(0)" onclick="SendEmail();">email</a>  
   </body>
</html>

Related Tutorials