S>Попробуй рассказать, зачем тебе это вообще надо.
Рассказываю:
I need to do some actions with a user when he reloads(F5, "Reload"
button, Ctrl+R) or closes the page. The Unload event is a good
approach here. However, it is not called in IE when
document.readyState != 'complete' (for example, the readyState for my
site is always 'interactive').
The only event I can go with is OnBeforeUnload. But every click on <a>
with href="javascript:" calls OnBeforeUnload.. So I need to detect
somehow what was the reason of this OnBeforeUnload, and if this reason
is not 'page reload' or 'close' I will just skip this event.
Unfortunately all my workarounds failed:
1) to set the onclick event for each link, where I set the flag and
check this flag in OnBeforeUnload.
It works, but I should set onclick on every application load event in
my ASP.NET api. So what to do with dynamically added controls which
contain anchors inside?
2) I noticed that __doPostBack also happens when we click on <a>. We
may override window.__doPostBack method (the same as to catch
document.forms[0].onsubmit event) where we also can set the flag and
check it up in OnBeforeUnload. But OnBeforeUnload may happen before
__doPostBack. So this method also doesn't pass..
3) To stop loading the document by using document.execCommand('Stop').
This is done to make readyState='complete' and use OnUnload instead of
OnBeforeUnload. But where we should place this stop-method??
Вот.. В общем, нужно узнать причину OnBeforeUnload (для этого я и хочу узнать,
как распознать клик по "Refresh"). Либо найти альтернативу событиям
OnBeforeUnload и OnUnload, чтобы в этой альтернативе выполнить нужные мне
действия над пользователем.