dhtml wrote:
[...]
Quote:
But for your case, you might not need all that, in which case a simple
attachEvent/addEventListener pair would work.
|
True, no need for major plug-in type libraries in this case.
At first I didn't realise attachEvent was for IE and addEventListener for
the better breed of browsers.
Anyway, all works in that if an onUnload call is present in the body tag
already, when the page unload event takes place, the attachEvent or
addEventListener will not overwrite any existing body call function, which
is exactly what I was looking for. For example:
<body onUnload="alert('hello from body tag')">
<script>
function rainbow(){
if (window.attachEvent){
alert('browser with window.attachEvent')
}
else if (window.addEventListener){
alert('browser with window.addEventListener')
}
}
/* run on IE 6, 7 etc. */
if(window.attachEvent){
attachEvent("onunload", rainbow)
}
/* or this for standard browsers */
else if(window.addEventListener){
addEventListener('unload', rainbow, true)
}
</script>
However, I don't understand whether to use true or false in the third
argument of the addEventListener function.
With the mozilla/firefox based browsers I'm testing the above example on
the effect is the same whether true or false, and although I find it
described on the following page I don't understand it:
http://developer.mozilla.org/En/DOM/...dEventListener
Does anyone have a simple example whereby true or false is relevant in
addEventListener? I guess it makes no difference on IE and with attachEvent
since the argument does not appear to exist.
Thanks for any tips!
Tuxedo