Solved

Detect scrolling in Internet Explorer using JavaScript

Posted on 2008-06-18
6
921 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now