views:

6798

answers:

6

Hi guys, Is it possible to disable the browsers vertical and horizontal scrollbars using jQuery or javascript?

+5  A: 

Try CSS

<body style="overflow: hidden">
codemeit
For browser compatibility I'd add this style to the HTML tag as well:html, body {overflow:hidden;}
Ady
Thanks for that, that is good,
codemeit
+10  A: 

In case you need possibility to hide and show scrollbars dynamically you could use

$("body").css("overflow", "hidden");

and

$("body").css("overflow", "auto");

somewhere in your code.

Alexander Prokofyev
A: 

Agree with CodeMelt, I don't even wanna know if there's a JS way to do that...

But be sure though to choose a size that fits small screens, like your boss' tiny winny notebook with a ridiculously small display, or you grandma's antic computer.

Vinzz
+1  A: 

Alexander Prokofyev is spot on, but it might be an idea to look at browser dimensions first, using jQuery, and make sure that the browser window is big enough to display the site correctly.

Samuel Cotterall
+2  A: 

So far we have overflow:hidden on the body. However IE doesn't always honor that and you need to put scroll="no" on the body element as well and/or place overflow:hidden on the html element as well.

You can take this further when you need to 'take control' of the view port you can do this:-

<style>
 body {width:100%; height:100%; overflow:hidden, margin:0}
 html {width:100%; height:100%; overflow:hidden}
</style>

An element granted height 100% in the body has the full height of the window viewport, and element positioned absolutely using bottom:nnPX will be set nn pixels above the bottom edge of the window, etc.

AnthonyWJones
A: 

In case you also need support for Internet Explorer 6, just overflow the html

$("html").css("overflow", "hidden");

and

$("html").css("overflow", "auto");
gawin