In my OnBeforeUnload event, it asked the user whether they want to leave the page or stay on it. When they click "stay on page", I want it to then redirect them to another webpage in the same window. Is there a way to do this, without just showing/hiding divs? Can I override the function?
Asked
Active
Viewed 4,025 times
0
-
1on before unload the user is planing to leave the page – Ibu Jul 08 '11 at 15:46
-
but when they click "stay on page", we want it to change what they were previously looking it - so therefore, "redirect" them to a new page. – Hani Honey Jul 08 '11 at 15:47
-
Like, is there some sort of override? – Hani Honey Jul 08 '11 at 15:48
1 Answers
0
Interesting!
Possible in Internet Explorer:
window.onbeforeunload = function()
{
window.onbeforeunload = null;
location.assign('http://example.com');
return "Warning message";
};
Firefox will go to the second page whilst waiting for your answer and then leave the page if you say so.
Chrome will always go to the second page, meaning the user cannot leave the page. So this might be a fantastically bad idea.
If the user is closing their window, it works alright though - but you can't tell if this is what the user wants.

Lee Kowalkowski
- 11,591
- 3
- 40
- 46