Solved

detect if a scroll bar is present or not

Posted on 2002-03-10
3
1,104 Views
Last Modified: 2007-11-27
Hi

Is it possible to find out if a document have the scrollbars (horizontal, vertical or both) currently displayed (visable)?

Sort of...

<script>
funtion findScrollBar(){
if (the scrollbars are currently being displayed){
alert ('scrollbars are visable');
}
else {
alert ('no scrollbars visable');
}
}
</script>

must not work in NS4

Hope someone can help!

Kind regards
Joergen
0
Comment
Question by:jastroem
3 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6854492
An IE only hack will do it, by test to see if the scrollbar exists by trying to reposition it:

<html>
<head>
</head>
<body>
hello
<script language="JavaScript">
<!--
    document.body.scrollTop+=10;
    if (document.body.scrollTop==0) alert('no vertical scroll bar');
    document.body.scrollLeft+=10;
    if (document.body.scrollLeft==0) alert('no horizontal scroll bar');

//-->
</script>
</body>
</html>


Cd&
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 50 total points
ID: 6855238
this would work in IE as well
if (document.body.clientHeight < document.body.scrollHeight)
{
 alert("vertical scrolling");
}

if (document.body.clientWidth < document.body.scrollWidth) {
 alert("horizontal scrolling");
}
0
 

Author Comment

by:jastroem
ID: 6857349
Dear Experts

Thank you for your solutions - which both works fine!
I give the points to b1xml2 - not for the reason that COBOLdinosaur's answer isn't good, it also works fine - because that script will not perform a short scrolling of the page to determine if the scroll bars are present or not.

Kind regards
Joergen
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

816 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

14 Experts available now in Live!

Get 1:1 Help Now