onunload有什么用呀,頁(yè)面都已經(jīng)關(guān)掉了
<!DOCTYPE?HTML> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"> <title>?卸載事件?</title> <script?type="text/javascript">? ????var?win; ?????window.onunload?=?onunload_message;??? ?????function?onunload_message(){??? ????????alert("您確定離開(kāi)該網(wǎng)頁(yè)嗎?");??? ????}??? ????function?openwin(){ ????????win?=?window.open("http://idcbgp.cn","_blank","width=300,height=300"); ????} ???? ????function?closewin(){ ????????win.onunload?=?onunload_message; ????????win.close(); ????} </script>??? </head> <body> ??歡迎學(xué)習(xí)JavaScript。 ??<input?type="button"?value="打開(kāi)新窗口"?onclick="openwin();"?/> ??<input?type="button"?value="測(cè)試彈窗關(guān)閉"?onclick="closewin();"?/> </body> </html>
如我的代碼,這樣頁(yè)面都已經(jīng)關(guān)掉了,這個(gè)提示還有什么用呢
2016-06-07
有的瀏覽器不支持
2016-06-07
比如小孩不小心把你正在看的電影一下關(guān)了,和跳出彈框之后再關(guān),當(dāng)然是確認(rèn)一下比較好。不過(guò)這個(gè)屬性不可以濫用,不然很影響用戶體驗(yàn)。