|
Posted by Michael Winter on 11/25/82 11:48
On 23/05/2006 21:28, Spartanicus wrote:
> How do I prevent this from executing twice when the window is resized:
>
> window.onresize = function () {
> alert('foo');
> }
The event is only dispatched to the body element once in Opera, so you
could add the listener there instead.
As the body property of the document object will initially be null, you
have three options:
1. <body onresize="/* ... */">
2. <body>
<script type="text/javascript">
document.body.onresize = function() {
/* ... */
};
</script>
3. <head>
<script type="text/javascript">
this.onload = function() {
document.body.onresize = function() {
/* ... */
};
};
</script>
> It has to work in Opera, what IE does is of no consequence.
All versions of Opera that dispatch the resize event (from 7.0, onwards)
will act as intended.
Just in case you care: IE will still fire multiple times, and Firefox
only supports the first option (it doesn't dispatch the event to the
body element at all).
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Navigation:
[Reply to this message]
|