gpt4 book ai didi

mailto - 防止单击 mailto 链接时调用 onbeforeunload

转载 作者:行者123 更新时间:2023-12-02 03:26:28 25 4
gpt4 key购买 nike

是否有办法阻止在 Chrome 中单击 mailto 链接时调用 onbeforeunload ?在 FF、Safari、IE 中运行良好。

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
google.load("jquery", "1.3.2");
</script>

<script type="text/javascript">
$(document).ready(function(){
window.onbeforeunload = confirmExit;
});

function confirmExit() {
return "Are you sure?";
}
</script>
</head>
<body>
<a href="mailto:someone@somewhere.com?subject=test mail&body=Hello%20World">Mail Link</a>
</body>
</html>

最佳答案

有什么解决方法吗?

$(document).ready(function(){
mailtoClicked = false;
window.onbeforeunload = confirmExit;
//Test if browser is Chrome
if (/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())) {
$('a[href^=mailto]').click(function() {mailtoClicked = true;});
}
});

function confirmExit() {
if (!mailtoClicked) {
return "Are you sure?";
} else {
mailtoClicked = false;
}
}

Demo .

关于mailto - 防止单击 mailto 链接时调用 onbeforeunload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1749052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com