Hi everyone,
I'm looking for a script that will make a confirm box when someone try's to exit the page. If the select yes, then it exits. If they select no, then it cancels the exit.
Any help?
Hi everyone,
I'm looking for a script that will make a confirm box when someone try's to exit the page. If the select yes, then it exits. If they select no, then it cancels the exit.
Any help?
http://www.google.com/search?q=onunload+confirm
But use it carefully: these scripts are very annoying.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Thanks for your help. I found this code
When I refresh the page the alert box comes up but when I exit it, nothing happens? Any help?HTML Code:<body onunload="alert('The onunload event was triggered')"> </body>
Are you using IE? I don't think the unonload event works in IE. It works in Chrome and Firefox though, I know that for sure.
- Mike
Generally when you see that kind of thing, pop up messages trying to prevent you from leaving, are associated with spam and untrustworthy content. Like Daniel said, be careful with it.
- Mike
I'd like to use it to tell advise them to log off (if they arn't already) before leaving the page.
If your website uses sessions, they will expire over time anyways. But I see your predicament. Maybe you need to look into something like cron jobs, or something. Is there any important information stored in the sessions? If not, there shouldn't be too much of an issue.
On a side note, you could still do the unonload thing, but it would only work in some browsers:
Code:<body onunload="if (confirm("You may need to log out before you leave.")) return false; ">
- Mike
Actually under some testing, that doesn't work either. Might take a little bit of digging to find the answer to this one.
- Mike
Try putting this in the head of your page:
Code:<script type="text/javascript"> function confirm(){ return "You need to log out."; } window.onbeforeunload = confirm; </script>
- Mike
Bookmarks