如何在点击 a 标签的 onclick 时间时,不触发 window.onbeforeunload 事件

时间:2024-05-01 08:16:44

如题!

直接贴代码了:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onbeforeunload = function ()
{
return "您确定要关闭添加文章页面吗?";
}
function showMessage(event)
{
alert('Hello World');
//event.cancelBubble = true;
//if (event.stopPropagation) event.stopPropagation();
return false;
}
</script>
</head>
<body>
<a href="javascript:void(0);" onclick="return showMessage(event);">点击看看</a>
</body>
</html>

运行截图:

关闭浏览器时:

如何在点击 a 标签的 onclick 时间时,不触发 window.onbeforeunload 事件

点击链接后:

如何在点击 a 标签的 onclick 时间时,不触发 window.onbeforeunload 事件

谢谢浏览!