Skipping OnBeforeUnload event

S

serge.bedulin

Hello!

I'm facing several problems with OnBeforeUnload event (only in IE).
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??

Maybe anyone knows how to solve such a problem? Many thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top