Forum Moderators: open

Message Too Old, No Replies

document.body.style.overflow = "hidden"; - not working in IE

         

designer123

3:58 am on Jan 29, 2008 (gmt 0)

10+ Year Member



document.body.style.overflow = "hidden"; - This is not working for me in IE, Working absolutely fine in FF..
On click i want to hide the scrollbar.

I tried alternatives like
document.getElementsByTagName("body")[0].style.overflow = "auto";
window.document.body.scroll = 'no';
but none of these work in IE, in firefox it disables the scrollbar as i needed but not in IE..is there any solution for this...

thanks - vicky

Fotiman

3:22 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you remember to set a width and height on body?

maa123

6:08 am on Feb 1, 2008 (gmt 0)

10+ Year Member



I tried this code and it works fine in IE and Firefox (ie no scrollbars) :

<html>
<body>
<div style="width:5000px; background-color:red">test</div>
</body>
<script>document.body.style.overflow = "hidden";</script>
</html>

- Maybe you have the overflow property defined also elsewhere, which overwrites this one.

To verify that install (if needed) Firefox with Dom Inspector, then when your page is loaded go to the tools menu -> 'Dom Inspector' or Ctrl-Shift-I. Then select the body tag in the left tree of the Dom Inspector. In the right pane choose in the menu : 'Object - Computed Style' instead of 'Object - Dom Node'. Now you can see below the computed (final) value of the overflow property for the body element.

- or maybe try to add : body {overflow:visible;} so you'll have :

<html>
<style>
body {overflow:visible;}
</style>
<body>
<div style="width:5000px; background-color:red">test</div>
</body>
<script>document.body.style.overflow = "hidden";</script>
</html>

The property overflow in the <style> is needed for IE and the same property overflow is needed in the <script> for Firefox. I don't know exactly why but it works for both IE and Firefox for me.

Achernar

2:02 pm on Feb 1, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



It depends on the doctype of the document.
If IE is in quirks mode, "document.body" (the <body> tag) is the element to apply the style to. With a valid doctype (HTML4 transitional or strict), you should apply the style to "document.documentElement" (the <html> tag).