Solved

detect if a scroll bar is present or not

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does GoogleTagMgr javascripts below do 5 35
Hide cell in a table 2 27
Making an "H1" a specific color only on a specific page. 3 27
Javascript 2 24
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.
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…
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…

828 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