1 回答

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