<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
alert("");window.location="index.html";
}
</script>
我在这里试过但没有工作请指导我
答案 0 :(得分:6)
所有内容加载完毕后,Windows onload就会加载,其他解决方法是使用document.onload(浏览器兼容性问题)
window.onload = function () {
window.location = "/allotment";
}
答案 1 :(得分:5)
在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
}
答案 2 :(得分:2)
下面的代码将适合您
function confirmExit()
{
alert("exiting");
window.location.href='index.html';
return true;
}
window.onbeforeunload = confirmExit;
答案 3 :(得分:0)
这对我有用。不是第二次尝试的部分,而是在显示弹出窗口后更改URL。如果单击取消,则不运行该功能。如果单击&#34;重新加载&#34;,则会调用该函数,您将被重定向。
$(window).on('beforeunload', function() {
$(window).on('unload', function() {
window.location.href = 'index.html';
});
return 'Not an empty string';
});
答案 4 :(得分:0)
在bbb.jsp文件中
<script>
submitFormOkay = false;
$(document.body).on("click", "a", function() {
submitFormOkay = true;
});
window.onbeforeunload = function(event) {
event.preventDefault();
if (!submitFormOkay) {
window.setTimeout(function () {
window.location = "index.html";
}, 0);
window.onbeforeunload = null;
}
}
</script>
我希望这会有所帮助。干杯!