views:

76

answers:

2

is there a way differentiate between refresh and close in Javascript? 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!

A: 

AFAIK, no there is no IE specific onclose event.

jeffreyveon
+1  A: 

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.

AlexV