onbeforeunload事件
它是這樣用的:
<script language="javascript">
g_blnCheckUnload = true;
function RunOnBeforeUnload() {
if (g_blnCheckUnload) {window.event.returnValue = 'You will lose any unsaved content';
}
}
</script>
<body onbeforeunload="RunOnBeforeUnload()">
</body>
這樣每次關閉瀏覽器窗口或涮新頁面時,都要觸發(fā)onbeforeunload這個事件。
http://www.surfchen.org/?p=54摘抄如下:
onbeforeunload事件:
注:三大主流瀏覽器中firefox和IE都支持onbeforeunload事件,opera尚未支持。
用法:
- object.onbeforeunload = handler
- <element onbeforeunload = “handler” … ></element>
描述:
事件觸發(fā)的時候彈出一個有確定和取消的對話框,確定則離開頁面,取消則繼續(xù)待在本頁。
handler可以設一個返回值作為該對話框的顯示文本。
觸發(fā)于:
- 關閉瀏覽器窗口
- 通過地址欄或收藏夾前往其他頁面的時候
- 點擊返回,前進,刷新,主頁其中一個的時候
- 點擊 一個前往其他頁面的url連接的時候
- 調用以下任意一個事件的時候:click,document write,document open,document close,window close ,window navigate ,window NavigateAndFind,location replace,location reload,form submit.
- 當用window open打開一個頁面,并把本頁的window的名字傳給要打開的頁面的時候。
- 重新賦予location.href的值的時候。
- 通過input type=”submit”按鈕提交一個具有指定action的表單的時候。
可以用在以下元素:
BODY, FRAMESET, window
平臺支持:
IE4+/Win, Mozilla 1.7a+, Netscape 7.2+, Firefox0.9+
posted on 2007-10-09 10:10
lk 閱讀(1966)
評論(1) 編輯 收藏 所屬分類:
ajax&js