onBeforeUnload

書式

<タグ onBeforeUnload = "イベント発生時の処理">
オブジェクト.onbeforeunload = "イベント発生時の処理"

説明

次のページに移動する時(リロードされた時も含む)に発生します。onUnloadイベントよりも前に発生します。また、returnで何か値を返すと(nullでも結果は同じ)、本当に他のページに移動するかどうかの確認ダイアログが表示されます。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<script type="text/javascript"><!--
window.onbeforeunload = function() {
alert("Before Unload");
return false;
}
// --></script>
</head>
<body>
<h1>onUnLoadサンプル</h1>
<p>不動産バブルは、いつ崩壊?</p>
</body>
</html>