I want to prevent a user from accidentally closing a browser window. I was curious if javascript could throw up a prompt window if someone clicks the X to close there browser.
although the X will close the window, if you put in the body tag 'onunload=' or 'onbeforeunload=', your effect will be...
onunload= will call a function first, then close the window...
onbeforeunload= (only in ie, i believe) will call a function, let's say a confirm prompt, thereby alerting the user to make certain they really want to close the browser window...if they confirm the close, the window closes, but if they click no, the window remains...
you know, you could throw the confirm pop up, and have it prompt the user like...
are you sure you want to logout?
and if the confirm, then on 'yes' click, run a function to log them out, then close the window...
once again i can't test this out as my comp box doesn't have the notepad.exe or any text editor...but if trouble persists, someone should be able to assist, or i'll check it out once i get home...
I am trying to implement this above and it works except that whenever I try to go to a diffrent page within the application it is giving me the alert box. I have placed the java in a header that is included on all pages and I did not need to put anything in the body tag to get it to work. Any ideas?
bcdeveloper
no you can not remove the OK or any button for that matter.
thysonj
post the code! You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.