Forum Moderators: open

Message Too Old, No Replies

onUnLoad Refresh in IE5.5 and IE6

onUnLoad is lost to the refresh action ... why and ho

         

joshie76

1:38 pm on May 31, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The onUnLoad event on a webpage uses some script to redirect to the logout page, for example.

<script>
function HandleUnLoad(){
window.top.location.href = "logout.htm";
}
</script>

...

<body onUnLoad="HandleUnload()" ....

This works fine for all browsers and UnLoad events EXCEPT for Refreshing on IE5.5/6. In these browsers the logout.htm page is called for a fraction of a second before being replaced by the page you clicked refresh on.

Any ideas on ways around this? Thanks in advance for you help. :)

Josh

tedster

6:37 pm on May 31, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm surprised that you don't get the same behavior in every browser. Since a refresh must first unload the current page, it should trigger the onUnload event handler. Microsoft's documentation [msdn.microsoft.com] explictly says this is what will happen.

The onUnload() method was originally conceived as a way to run a short clean-up script that would undo any lingering effects of scripts run in the window; in essence, a way to take out the garbage. Nevertheless many people use it for other purposes, the notorious exit pop-up window being a prime offender.

None of which solves your problem, I realize. I was considering a script to tell the difference between a refresh and other types of unLoad, but there's no way for JavaScript to detect what page is going to load next (that would create a big security hole).

You've go me stymied.

joshie76

8:21 am on Jun 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"You've go me stymied." What does that mean?

We've managed to get around it by inserting a small page containing js.

If this loads the onLoad event redirects it to the logout page. If it doesn't finish loading then the browser action just continues... this is fine as the problem only occurs on a refresh.

A bit of browser sniffing avoids doing this unnecessarily.

J

tedster

4:46 pm on Jun 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> "You've go me stymied." What does that mean? <<

It's a slang term (derived from playing marbles, I think) that means baffled, or blocked from a response.

Sounds like you've got a clever work-around. I'm filing that tidbit away -- could come in handy.

joshie76

7:57 am on Jun 4, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just for your records:

You might be interested to know that, on the onUnLoad event (in the case discussed above), whilst the redirect target never actually loads the HTTP request IS made so any server side ASP (or whatever) is executed.

J