[Javascript] turning on scrollbars

Hassan Schroeder hassan at webtuitive.com
Tue Jan 6 11:51:59 CST 2004


Dan Anderson wrote:

> Is there a way in javascript to turn on and off a scrollbar in a
> document after its been loaded?

Uh, not sure *why* you'd want to do this, since the scrollbar only
appears if the page content won't fit within the viewport, but ...

This works in Moz/Firebird 0.7, IE 5.5, Opera 7.22 (Win):

<script type="text/javascript">
function init()
{
   /* these first two lines are only necessary for Moz; not sure
    * why its computation of height differs, at least in my very
    * brief test... alternate: see CSS below --
    */	
   document.getElementsByTagName("html")[0].style.height="100%";
   document.getElementsByTagName("body")[0].style.height="95%";

   document.getElementsByTagName("body")[0].style.overflow="hidden";
}
window.onload = init;
</script>

You can also set the heights for Moz statically, as:

<style type="text/css">
html {
	height: 100%;
	clip: auto;
	}
body {
	height: 95%;
	clip: auto;
	}
</style>

FWIW!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.






More information about the Javascript mailing list