So the best way is to let the user acknowledge the page transition while using the backspace button. It is possible to use an onbeforeunload event to confirm leaving the page, but this event also wants confirmation on following links and other exiting events.
I solved the program with the following javascript code:
var bConfirmExit = false;
function closeIt()
{
if (bConfirmExit)
{
event.returnValue = "Bij het verlaten van deze pagina verliest u de ingevoerde gegevens.";
}
}
function resetExit()
{
bConfirmExit = false;
}
function checkBS()
{
if (event.keyCode == 8)
{
bConfirmExit = true;
setTimeout("resetExit()",200);
}
}
and linked the following events in the body tag:
<body onbeforeunload="closeIt()" onkeydown="checkBS()">
No comments:
Post a Comment