Link to home
Start Free TrialLog in
Avatar of jastroem
jastroem

asked on

detect if a scroll bar is present or not

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
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

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&
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jastroem
jastroem

ASKER

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