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
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.
精彩评论