Entry
onunload event is not working in netscape. How do I use onunload event in netscape
Can somebody please tell me how to detect browser close using Netscape; OnUnload doesnt work when th
Mar 8th, 2007 01:17
Shaun Doe, Namdev Shenoy, Ralph Meier, Mike Gorski, Juergen Thelen, Hitesh Kapadia,
Sorry, but afraid onUnload DOES work fine in NN. Try this, for example:
<body onUnload="open('http://www.netscape.com');"> (This doesnt work
when you close the Netscape browser?)
You'll see, it works... :o)(Doesnt work???)
The only problem I could imagine is, that you try to use alerts inside
your onUnload event handler, and you're wondering why stuff like this
won't be visible, or will just flicker for a moment and then disappear.
That's due to javascripts asynchronous execution behaviour. It will
not
wait for your alert box to be shown, and least of all wait for a users
click in your alert box. Instead javascript will immediately execute
the next line(s) in your event handler.
So usually your event handler will exit faster, than the users system
can build and display your alert box, or the user can confirm your
alert box.
Now, on exit of your handler all running and pending functions of the
page will be automatically canceled and garbaged by the browser,
including your alert box, of course...
In other words, your alert box will simply be swallowed... :o)
Hth, Juergen
Ralph Meier:
Indeed, the onUnload-Event is not to be handled by Netscape if the
user
close the window by clicking the "x"-Button.
Try by yourself, Juergen:
<html><head><title>Test</title>
<script type="text.javascript">
var Start = new Date();
var Starttime = Start.getTime();
function duration() {
var End = new Date();
var Endtime = End.getTime();
var duration = Math.floor((Endtime - Starttime) / 1000);
alert ("You have watched this site for "+duration+" seconds.");
}
</script>
</head>
<body onUnload="duration()"
some content here
<p><a href="http:.www.google.de"><b>Go to somewhere.</b></a></p>
</body></html>
The link works fine, but if I close the Netscape-window my function is
not to be called.
Maybe, anyone could explain how to work around this problem?
Thanks in advance!
Ralph aka. Yoshi
Hi,
This example works fine in Netscape 7.1 and higher (does not work in
7.0)
Shenoy
--------------------------------------
If your version of Netscape is 4.2 and below there is no known way to
capture/use javascript closing events
Ryder