[英]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.