1

i am doing a popup alert like this:

window.onbeforeunload = confirmExit;
function confirmExit()
{
return "Wait! Save up to $20 Today! \n nClick OK to Save";
} 

when i close the window i vet Stay on the page and Close the browser or something similar

what i am trying to do is: if Stay on the page option has been chosen then i want to eighter redirect the user to another page or show a jquery popup.

something similar to:

if (window.onbeforeunload = null){
location.assign('http://example.com');
}

but this doesn't work.

Any ideas?

Thanks

Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
  • Similar question: http://stackoverflow.com/questions/1335727/onbeforeunload-confirmation-screen-custumization – v42 Sep 14 '11 at 19:45
  • Such a message is really annoying. You might want to consider removing it, because users won't be amused by it. – pimvdb Sep 14 '11 at 19:48

1 Answers1

2

As pimvdb said in his comment to your question, this is a really annoying thing to do and I highly recommend against it. It's just going to piss off your potential customers and ensure they don't want to come back to your site later.

That said, here's something you can try. I'm not positive it'll work, I could see there being some safeguards in place to prevent you from mucking with things while the window's unloading, but I'd do something like:

window.onbeforeunload = confirmExit;
var triedToExit = false;
function confirmExit()
{
  triedToExit = true;
  return "Wait! Save up to $20 Today! \n nClick OK to Save";
}

From there you have some function checking every so often to see if triedToExit is set, and if it is, you can forward them as normal.

But really, don't do this.

Asmor
  • 5,043
  • 6
  • 32
  • 42