代码改变世界

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

2013-09-17 18:15  音乐让我说  阅读(733)  评论(0编辑  收藏  举报

如题!

直接贴代码了:

<!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>

 

运行截图:

关闭浏览器时:

点击链接后:

 

 

 

 

谢谢浏览!