Discussion Locked

jsp onbeforeunload equivalent

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I know that onbeforeunload is an IE-only event handler. I need an equivalent to prevent the user from closing the winsow that works on all browsers.

3 replies

by nikki96

There isn't one that works on ALL browsers. Some browsers don't even support javascript (Lynx).
But you can try onunload. That's a popular choice.

Also keep in mind many users have tabbed browsers. There is no guarantee they have your stuff open in a window at all. Might be a tab. MSIE7 will also have tabs.

by dfirefire

While it can be useful to prevent users from closing windows (e.g. in a corporate environment, to keep the businees app open...), it is not really a good programming practice, and therefore, not evenly implemented by all browsers (otherwise, it should be). It even is a bit intrusive, as window management is the responsability of the user (and the OS) in the end. As stated in the first answer, you can never be sure what kind of device is going to display your code, and what sorts of code (e.g. JavaScript) it is going to support. Taken that you do have the right reasons and rights to take this kind of control over your client's machine, then, unfortunately, the web-based interface is the wrong medium...

by chief bottle washer

If you force the window to stay open onunload and the end user
really wants it closed that end user may never visit your site
again.

This discussion is closed to new replies.