Chrome瀏覽器,剛進入或者刷新的時候才有提示,關(guān)閉的時候沒有提示了?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> 卸載事件 </title>
<script type="text/javascript">? ?
? ? ?window.onunload = onunload_message;? ?
? ? ?function onunload_message(){? ?
? ? ? ? alert("您確定離開該網(wǎng)頁嗎?");? ?
? ? }? ?
</script>? ?
</head>
<body>
? 歡迎學(xué)習JavaScript。
</body>
</html>
2020-02-19
<script type="text/javascript">? ? ??
? ? ? window.onbeforeunload = onbeforeunload_handler;? ??
? ? ?function onbeforeunload_handler(){??
? ? ? ? ?var warning="";? ? ? ? ??
? ? ? ? ?return warning;??
? ? ?}? ?
?</script>??
2020-06-03
調(diào)用函數(shù)要添加(),window.onbeforeunload = onunload_message()
2020-02-19
經(jīng)過多次嘗試,onunload打開頁面和關(guān)閉頁面都沒有任何提示,建議使用onbeforeunload