<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
alert("");window.location="index.html";
}
</script>
I tried this code, but it is not working.
In 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
}
below code will work for you
function confirmExit()
{
alert("exiting");
window.location.href='index.html';
return true;
}
window.onbeforeunload = confirmExit;
Windows onload loads after all the content is loaded, little bit slow other workaround is to use document.onload(Browser compatibility issue)
window.onload = function () {
window.location = "/allotment";
}
In bbb.jsp file
<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>
I hope this will help. Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With