I was tried to track when a user is just going to away from a web page by using JavaScript. That was pretty possible with the window.onbeforeunload it worked fine. But fine until my project QA team found that it does not work with Internet Explorer 7.
window.onbeforeunload is working with the Firefox and IE 6 but it does not work with IE 7 (in the same manner with other browsers). So I was able to find a solution for that.
var goodExit = false;
window.onbeforeunload = confirmExit;
function = confirmExit()
{
if(your any condition)
{
goodExit = true; //then that confirmation will not be asked
}
if(!goodExit)
{
return 'Are you sure to navigate away ?'; //this will display on confirmation
}
}
//there should not any returns on the function confirmExit.
You can make the goodExit true when the page is doing submit or any other that we do not need a confirmation.And also do not assign true or false to window.onbeforeunload. Because it may lead to a script error on IE 7.
Comments
Post a Comment