开发者

Can we capture an event when user presses X on the browser window?

开发者 https://www.devze.com 2022-12-17 19:39 出处:网络
is there a way differentiate between refresh and close in Javascr开发者_开发技巧ipt? i use window.onbeforeunload now which works great in IE. To void this being called anywhere but close, i set a flag

is there a way differentiate between refresh and close in Javascr开发者_开发技巧ipt? i use window.onbeforeunload now which works great in IE. To void this being called anywhere but close, i set a flag on EVERY button ...this seems like a difficult, hacky solution, but after searching for hours on google, it was the best i could find.

Isn't there an onclose event for IE????? or onclick?

I only need to support IE, not FF, so please don't post anything FF related, I can't use it. Thanks!


As far as I know there is no way to trap in JavaScript the click of the X (close) button in any browser. In my opinion this is due to security concern... JavaScript can't (an will never be able to) listen to OS messages like the close of the current window.

The only solution I know (which is what you seem to use) is:

<body onunload="alert('Fired');">

But as you find out if fires on close and on reload. Again this is normal behavior because, AFAIK, for the JS engine a reload is the same as a close then a reopen of the same page.


AFAIK, no there is no IE specific onclose event.

0

精彩评论

暂无评论...
验证码 换一张
取 消