Is there a javascript function that when you press the close button at the top right hand corner of your browers will prompt you and say:
Are you sure you want to close:
yes or no
Thanks.
| SitePoint Sponsor |




Is there a javascript function that when you press the close button at the top right hand corner of your browers will prompt you and say:
Are you sure you want to close:
yes or no
Thanks.



There's such a thing as an "onunload" event.
You can have "window.onunload", which will be triggered when the window is closed.
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
April Photo-Challenge: "A Piece of Paper"




Is there a way to disable the exit or back button then?
Code:<html> <head> <title>test</title> <script language="javascript" type="text/javascript"> window.onbeforeunload = keep_open; function keep_open(){ return "Are you sure you'd like to exit this page?"; } </script> </head> <body> MY WEB SITE!!!! </body> </html>



window.onbeforeunload...
Well I can't say I knew about that one.
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
April Photo-Challenge: "A Piece of Paper"



What the hell are you up to??Originally Posted by wickedneat
To disable the back button, all I can think of is to launch a new window or have some blank intermediary page that redirects to the final page, so that if someone clicks "back" they'd return to the blank page and it'd kick them back to your final page regardless.
Of course if they click back multiple times they'd probably get around it.
Last edited by Shaun(OfTheDead); Aug 1, 2007 at 04:46. Reason: typo
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
April Photo-Challenge: "A Piece of Paper"



I don't think there's a way to disable the exit button, though. It'd be too much of a security risk.
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
April Photo-Challenge: "A Piece of Paper"
Bookmarks