Re: DOM event flow



Michael Winter <m.winter@xxxxxxxxxxxxxxxx> 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>

Thanks, I used #3.

In trying to take it one step further I'd like the function to execute
only when the window width changes. First I should illustrate what I'm
trying to do.

Opera has a preliminary implementation of CSS3 media queries, this
allows dissolving a multi column layout for narrower window widths.
Currently the CSS media query isn't reevaluated on a window resize, it
requires a reload, so I'm using JS to do that:

http://homepage.ntlworld.com/spartanicus/css_layout.htm

Ideally I'd like the reload only to occur if the viewport width changes.
After a glance in a JS book and not hindered by a proper understanding
of JS & the DOM I tried:

<script type="text/javascript">
window.innerWidth.onresize = function() {
location.reload(false);
};
</script>

But no go, any idea if this refinement is possible?

--
Spartanicus
.



Relevant Pages

  • Re: OT - Woodstocks in Venice - Part the Second
    ... spent a lot of time in less touristy neighborhoods ... opera. ... A Venetian matron, perhaps in her seventies, was ... | in every window - whirligigs, banners, flags, windsocks, all in colorful ...
    (rec.arts.mystery)
  • [VulnWatch] Opera: Location, Location, Location
    ... Opera 7.53 and prior on Windows, ... The advisory depicted several flaws in Opera's ... write-access to objects on the victim window. ... GreyMagic Software is not liable for any direct or indirect damages caused ...
    (VulnWatch)
  • [Full-Disclosure] Opera: Location, Location, Location
    ... Opera 7.53 and prior on Windows, ... The advisory depicted several flaws in Opera's ... write-access to objects on the victim window. ... GreyMagic Software is not liable for any direct or indirect damages caused ...
    (Full-Disclosure)
  • Advisory : Opera Window Object Suppressing Remote Denial of Service
    ... Opera Window Object Suppressing Remote Denial of Service. ... directly by default which makes it vulnerable to denial of service attack. ... SecNiche confirmed this vulnerability affects Opera on Microsoft ...
    (Bugtraq)
  • Opera: Location, Location, Location (GM#008-OP)
    ... Opera 7.53 and prior on Windows, ... The advisory depicted several flaws in Opera's ... write-access to objects on the victim window. ... GreyMagic Software is not liable for any direct or indirect damages caused ...
    (Bugtraq)