Solved

detect if a scroll bar is present or not

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now