Solved

Detect scrolling in Internet Explorer using JavaScript

Posted on 2008-06-18
6
925 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
Industry Leaders: 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Handling case and special names in javascript 3 51
jquery change div image on page reload using Jquery 9 57
Conformation code 4 35
Json and ajax javascript 24 23
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
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 +…

734 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