我想事件onbeforeunload類似下面,它工作正常,當我關閉瀏覽器離開現場JavaScript事件 - onbeforeunload - 刷新頁面/內部的超鏈接
<script type="text/javascript" language="javascript">
window.onbeforeunload = LeavingSiteHandler;
function LeavingSiteHandler(e) {
if (!e)
e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
</script>
然而,當我按F5刷新頁面或點擊在內部鏈接上,此事件將被解僱。是否有可能檢查點擊的超鏈接是否是內部鏈接?如果我按F5,是否可以停止彈出消息? 非常感謝!
除非事情已經改變,該網站說,這基本上是不可能的:http://www.webdeveloper.com/forum/showthread.php?t=202588。 – pimvdb 2011-03-31 14:51:40