?
Solved

Detect scrolling in Internet Explorer using JavaScript

Posted on 2008-06-18
6
Medium Priority
?
930 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Accepted Solution

by:
Badotz earned 300 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 +…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 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