Click here to Skip to main content
12,694,121 members (32,636 online)
Click here to Skip to main content
Add your own
alternative version


6 bookmarked

Detect Scrollbars Presence

, 18 Sep 2007
Rate this:
Please Sign up or sign in to vote.
Detect Scrollbars Presence


This javascript will help you to detect presence of scrollbars (either x or y or both) for a div tag. Just pass the parameters (div Id and Aces i.e. which side of scrollbar x or y or both you want to detect) to the javascript function and you will know whether the scroll bar exist or not. The second parameter (Aces) is optional, you can leave this blank if you are not sure which scrollbar could exist and you want to detect whichever (x or y) scrollbar is exist. The attached sample file detect_scrollbars_div.aspx will show few examples. This javascript was only tested on Microsoft Internet Explorer version 6.0 in VWD 2005 Express Edition environment. This is a free javascript distributed in the hope that it will be useful but without any warranty.


I wanted to show customized scrollbars left/right buttons if the scrollbars exist. The reason of showing the customized scrollbars buttons is that my div has a limited size and show dynamic contents. In some case the contents are wider than the division width. If I show the standard scrollbar (overflow:auto) that mess up my div look. Another reason is that I only wanted to show the customized scrollbars left/right buttons only if the scrollbar is presence otherwse the customized left/right buttons also disappear. Therefore I wrote this simple and show javascript to detect if the scrollbar is exist, if yes then the customized scrollbar buttons appear.

Using the code

The javascript is very simple and straight forward. Looking at the code you will know how to use it. Simply pass the parameters and which side of scrollbar you want to check. If you are not sure which scrollbar could exist just pass the to the javascript function.

Points of Interest

Cool and simple coding.


Created by: Muhammad Shoaib

Created on: 18 Sept 2007


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

QuestionSuggestion Pin
philipp.germany24-Jan-12 2:30
memberphilipp.germany24-Jan-12 2:30 
GeneralI like it Pin
cmschick8-Feb-09 4:32
membercmschick8-Feb-09 4:32 
GeneralCool Pin
Tom Hawkins11-Oct-07 13:15
memberTom Hawkins11-Oct-07 13:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 19 Sep 2007
Article Copyright 2007 by Muhammad Shoaib Patel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid