<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
alert("");window.location="index.html";
}
</script>
このコードを試しましたが、うまくいきません。
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
alert("");window.location="index.html";
}
</script>
このコードを試しましたが、うまくいきません。
でbbb.jsp
:
window.onbeforeunload = function() {
window.setTimeout(function () {
window.location = 'AAA.jsp';
}, 0);
window.onbeforeunload = null; // necessary to prevent infinite loop, that kills your browser
}
以下のコードはあなたのために働きます
function confirmExit()
{
alert("exiting");
window.location.href='index.html';
return true;
}
window.onbeforeunload = confirmExit;
これは私にとってはうまくいきました。2回目の試行部分ではなく、ポップアップ表示後にURLを変更。キャンセルを押すと、関数は実行されません。「リロード」をクリックすると、関数が呼び出されてリダイレクトされます。
$(window).on('beforeunload', function() {
$(window).on('unload', function() {
window.location.href = 'index.html';
});
return 'Not an empty string';
});