Solved

Detect scrolling in Internet Explorer using JavaScript

Posted on 2008-06-18
6
923 Views
Last Modified: 2013-12-08
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
0
Comment
Question by:Gagik
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 21815168
Show us how you do it for Mizilla (sic).
0
 

Author Comment

by:Gagik
ID: 21815655
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
 

Author Comment

by:Gagik
ID: 21815687
apparently in IE it should be: document.body.scrollTop

but when i try it with my IE it doesn't work
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 29

Accepted Solution

by:
Badotz earned 75 total points
ID: 21815692
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
 

Author Closing Comment

by:Gagik
ID: 31468479
it finally worked, thanks a lot!!!!
0
 
LVL 29

Expert Comment

by:Badotz
ID: 21818824
No worries - glad to help.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript/CSS: Detect if hue-rotate supported by browser 1 37
Web forms being filled out by bots 4 34
Html5 Index on a table 7 26
Javascript Form Change 5 20
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question