為什么我這個(gè)沒有任何反應(yīng)啊,而且編譯器還有報(bào)錯(cuò)
<!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é)習(xí)JavaScript。
</body>
</html>
報(bào)錯(cuò):Blocked alert('您確定離開該頁面嗎?') during unload.
解決不了啊
2023-11-11
function上面那行message要加括號(hào)
2021-10-09
代碼沒有問題的話,可能是瀏覽器不支持onunload
2021-08-26
注意:不同瀏覽器對(duì)onunload事件支持不同。