簡體   English   中英

打開mailto鏈接並關閉頁面

[英]Open mailto link and close page

有沒有辦法讓頁面打開mailto鏈接並立即關閉打開該鏈接的頁面? 現在我有以下代碼:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript">
       window.location.href = "mailto:test@domain.com";
    </script>
  </head>
  <body>
     <a href="mailto:test@domain.com">Test</a>
</body>
</html>

當我導航到該頁面時,郵件客戶端已打開,但頁面保持打開狀態,這是我寧願沒有的。

您可以使用 Window.close() function 無論您的瀏覽器是什么,它都能正常工作。

<html>
  <head>
    <script type="text/javascript">
       //window.location.href = "mailto:test@domain.com";
       function openClose(url){
           newTab = window.open(url) // Default open target is "_blank" aka new tab
           newTab.close() // Window class have this method
           // Automatically close the tab when email client starts
       }
    </script>
  </head>
  <body>
     <a onclick="openClose('mailto:test@domain.com')" href="#">Test</a>
     <!-- i set the "href" to "#" because of nothing :) -->
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM