Solved

detect if a scroll bar is present or not

Posted on 2002-03-10
3
1,111 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
[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 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

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!

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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.
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…

691 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