Detect scrolling in Internet Explorer using JavaScript

Hi,

I need to detect scroll bar size or simply have access to a variable that holds scroll bar information in INTERNET EXPLORER using JavaScript.

I already know how it works for Mizilla but I can't make it work fo IE.

thanks a lot
GagikAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
BadotzConnect With a Mentor Commented:
In Firefox, you would use the window.pageYOffset or window.pageXOffset to get these positions. In IE, you would use document.documentElement.scrollTop or document.documentElement.scrollLeft.

So, to handle both browsers, a simple function to do this would be:
function getYOffset() {
    var pageY;
    if(typeof(window.pageYOffset)=='number') {
       pageY=window.pageYOffset;
    }
    else {
       pageY=document.documentElement.scrollTop;
    }
    return pageY;
}
 
/*
 
 This is from a Google search for:
 
 IE window.pageYOffset
 
 This was the first result:
 
 http://thought-bytes.blogspot.com/2007/02/ie-and-firefox-scroll-offsets.html
 
 */

Open in new window

0
 
BadotzCommented:
Show us how you do it for Mizilla (sic).
0
 
GagikAuthor Commented:
in mozilla i use this: window.pageYOffset

It gives me a number in pexales by which the page has been offeset vertically due to the scroll.

any ideas how to do it with IE ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
GagikAuthor Commented:
apparently in IE it should be: document.body.scrollTop

but when i try it with my IE it doesn't work
0
 
GagikAuthor Commented:
it finally worked, thanks a lot!!!!
0
 
BadotzCommented:
No worries - glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.