1 回答

TA貢獻123條經(jīng)驗 獲得超103個贊
onunload 網(wǎng)頁卸載了之后
onbeforeunload 網(wǎng)頁卸載了之前
onunload 如果你只有一個當(dāng)前網(wǎng)頁,那么關(guān)了之后瀏覽器就關(guān)了 是不會彈窗的 。
反之?onbeforeunload ?是在你點關(guān)閉之前就彈窗確認
<!DOCTYPE HTML>
<html>
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
? ?<title>onbeforeunload測試</title>
? ?<script>
? ? ? ?function checkLeave(){
? ? ? ? ? ?event.returnValue="確定離開當(dāng)前頁面嗎?";
? ? ? ?}
? ? ? ?
? ?</script>
</head>
<body onbeforeunload="checkLeave()">
</body>
</html>
//測試下面這個記得多開一個網(wǎng)頁<!DOCTYPE HTML>
<html>
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
? ?<title>onunload測試</title>
? ?<script>
? ? ? ?function checkLeave(){
? ? ? ? ? ?alert("歡迎下次再來!");
? ? ? ?}
? ?</script>
</head>
<body onunload="checkLeave()"> ??
</body>
</html>
添加回答
舉報