[Javascript] scrollbars

Andrew Clover and-babble at doxdesk.com
Thu Mar 31 09:22:15 CST 2005


Dash <forgetful54341087097153001984 at hotmail.com> wrote:

> does anyone know how to change the visibility of a pages scrollbars,
> or if it's even possible?

In Mozilla and Opera (and probably others) scrollbars will only appear 
if the content of the page is too long to fit the window.

In IE/Win, a page scrollbar will appear all the time, but be greyed out 
if the content is not too long. IE does indeed allow this to be changed 
with the 'overflow' attribute, though, so this:

> could it be done with something like:
> document.getElementsByTagName("body").item[0].style.overflow="auto"

is nearly right. Firstly, HTMLCollection.item() is actually a function 
so you want round rather than square brackets, or just use collection[0] 
as a short-cut. Anyway, document.body is a much quicker way to express it.

Secondly, the element which IE makes the visual root and thus gives 
scrollbars changes. In IE5 and Quirks mode it's <body>, in IE6 Standards 
mode it's <html>. (The standards actually say it shouldn't be either of 
them, but that's another story.) So to do it in either mode:

   if (ie_win) { // sniffed using whatever is your favourite method
     var r;
     if (document.compatMode=='CSS1Compat')
       r= document.documentElement;
     else
       r= document.body;
     r.style.overflow= 'auto';
   }

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Javascript mailing list