次のコードを使用して、ユーザーがブラウザ ボタンを閉じると、ページに留まるかどうかを確認するボックスが表示されるようにします。
私がやりたいことは、誰かがブラウザを閉じたときに、「はい」または「いいえ」のオプションで画像を表示することです。「はい」をクリックするとブラウザを閉じ、「いいえ」をクリックするとブラウザを閉じません。画像は、ポップアップではなく同じウィンドウに表示する必要があります。それは可能ですか、それとも JavaScript に期待しすぎているのでしょうか?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var exit=true;
function confirmExit()
{
if(exit)
{
window.location.href = "?p=exit";
}
if(exit)
return "Wait! Don't Leave Empty Handed!\n\nThank you for taking the time to check out our offer! Before you go we have a complimentary crash to help you succeed. Click the 'Cancel' or 'Stay On This Page' button if you're interested!";
}
</script>
</head>
<body onbeforeunload="return confirmExit()">
</body>
</html>