orion3
orion3

Reputation: 9935

How to know if the scrollbars has appeared in browser (jQuery)?

I need to know, whether a vertical scrollbar has appeared or not in browser window. Is it possible using jQuery or any other way?

Upvotes: 6

Views: 8832

Answers (3)

Aximili
Aximili

Reputation: 29474

This is an old post but I finally got the code that also works on IE7. Hope this can help someone.

var hasScrollbar = $('body').outerHeight() > $(window).height();

Upvotes: 4

SLaks
SLaks

Reputation: 887433

Like this:

if (document.documentElement.scrollHeight === document.documentElement.clientHeight) {
    //There is no vertical scrollbar
}

This doesn't work in IE

Upvotes: 7

CharlesLeaf
CharlesLeaf

Reputation: 3201

Compare the document height with the window height. If it's more there's probably a scrollbar unless you disabled it.

Upvotes: 1

Related Questions