Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: onScroll event (using Prototype) doesn't work on IE?

I am trying to trigger the onScroll event this way using prototype:

Event.observe(document, 'scroll', function(){
    alert('boo');
});

It works perfectly on Firefox, but nothing happens on IE. Does anyone know why? and if there is another way to do so?

Thanks

like image 655
Chetane Avatar asked Jul 07 '09 05:07

Chetane


2 Answers

Try attaching it to the window instead:

Event.observe(window, 'scroll', function() {
        alert('boo');
});

Works for me on IE, FF. Honestly, I don't know why it would work attaching it to the document.

like image 103
Paolo Bergantino Avatar answered Oct 16 '22 13:10

Paolo Bergantino


Don't know if anyone is still following this answer, but i thought i would put down some of the information i found. In general the scroll event is supported on "window" on the following browsers below...

  • IE 5,6,7,8 (don't know about 9)
  • FF all versions
  • Safari 3.0.. up
  • Chrome
  • Opera 9.0.. up

However, when it comes to the document, it is not supported on any of the IE versions. Now, the funny thing is the Iphone 3G browser is the reverse of IE. The scroll event only works on the document. For more info on this, check out http://www.quirksmode.org. This site has alot of good stuff on event handling. Hope this helps someone...

like image 36
The Code Pimp Avatar answered Oct 16 '22 14:10

The Code Pimp