window.onbeforeunload
from:

I need to "redirect" after clicking CANCEL onbeforeunload.

So... On Before Unload, confirm appeared. If I click OK, the window will close, if I click CANCEL I'm staying on current page.

So... I need after clicking CANCEL to redirect to another page.


window.onbeforeunload = function(e) { e.returnValue="My custom message"; window.location="http://www.google.com"; }; Code (markup):

The problem with this code is that "window.location" execute on before...

window.onbeforeunload

Poster :
sojic