打开mailto链接并关闭页面

问题描述 投票:0回答:1

是否有办法让页面打开mailto链接并立即关闭打开该链接的页面?现在我有以下代码:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript">
       window.location.href = "mailto:[email protected]";
    </script>
  </head>
  <body>
     <a href="mailto:[email protected]">Test</a>
</body>
</html>

当我导航到该页面时,邮件客户端已打开,但随后该页面保持打开状态,这是我不希望的。

javascript html
1个回答
0
投票

<html>
  <head>
    <script type="text/javascript">
       //window.location.href = "mailto:[email protected]";
       function openClose(url){
           newTab = window.open(url)
           newTab.close() // Automatically close the tab when email client starts
       }
    </script>
  </head>
  <body>
     <a onclick="openClose('mailto:[email protected]')" href="#">Test</a>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.