Most Bizarre IE Quirk

I was playing around with timers the other day, trying to see how different browsers handled different edge cases, when I stumbled across a fascinatingly bizarre quirk in Internet Explorer. I wouldn’t call it a bug, per se, since that would imply that there was an excepted result, but there is not. The code:

}, -1);

Now, before you view the demo (view in IE only!) try to guess what the above code does.

Since -1 isn’t a valid interval my guess was that it would, either (based upon Internet Explorer’s current setInterval behavior):

  1. Execute immediately, like a normal function, but then never fire again.
  2. or not execute at all.

What happened is positively bizarre: The callback function will be executed every time the user left clicks the mouse, anywhere in the document.

I find this to be absolutely hilarious. I’m struggling to think of how this could, possibly, be used in any remotely feasible way. Some random ideas:

  • A global click handler that can’t be removed and doesn’t leak memory (presumably since no DOM elements involved?)
  • Some sort of vector for XSS attacks. I don’t know what the situation would be where you have access to setInterval but not the DOM, so I’m not sure what credence this has.
  • A way to initiate a fake event capturing click event (before the actual bubbling event occurs).

I don’t know – I’m not sure if any of them are terribly useful but I find it to be amusing nonetheless. Thoughts on how we can have fun with this?

Posted: February 16th, 2008

Subscribe for email updates

28 Comments (Show Comments)

Comments are closed.
Comments are automatically turned off two weeks after the original post. If you have a question concerning the content of this post, please feel free to contact me.

Secrets of the JavaScript Ninja

Secrets of the JS Ninja

Secret techniques of top JavaScript programmers. Published by Manning.

John Resig Twitter Updates

@jeresig / Mastodon

Infrequent, short, updates and links.