5 回答

TA貢獻(xiàn)83條經(jīng)驗(yàn) 獲得超67個(gè)贊
<body??onunload="alert('歡迎您再來(lái)')"?> <script> ????window.onbeforeunload=function?(){ ????????alert("===onbeforeunload==="); ????????if(event.clientX>document.body.clientWidth?&&?event.clientY?<?0?||?event.altKey){ ????????????alert("你關(guān)閉了瀏覽器"); ????????}else{ ????????????alert("你正在刷新頁(yè)面"); ????????} ????} </script>
onload 事件和onunload事件 正好相反。這樣就能看到效果了(ie瀏覽器 能看到效果)

TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超0個(gè)贊
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="utf-8">
? ? <title>onload 和 onunload 事件</title>
</head>
<body onload="load()" onunload="unload()" >
? ? <script>
? ? function load() {
? ? ? alert('go')
? ? }
? ? ?function unload() {
? ? ? alert('gggggg')
? ? }
? ? </script>
? ? <p>彈窗-提示瀏覽器 cookie 是否可用。</p>
</body>
</html>

TA貢獻(xiàn)56條經(jīng)驗(yàn) 獲得超22個(gè)贊
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="utf-8">
? ? <title>onload 和 onunload 事件</title>
</head>
<body onload="load()" onunload="unload()" >
? ? <script>
? ? function load() {
? ? ? alert('go')
? ? }
? ? ?function unload() {
? ? ? alert('gggggg')
? ? }
? ? </script>
? ? <p>彈窗-提示瀏覽器 cookie 是否可用。</p>
</body>
</html>
添加回答
舉報(bào)