views:

78

answers:

4

Hi there,

I want to always show vertical scrollbar in my webpage. How it is possible using javascript? I think it is possible using javascript or jQuery. I want vertical scrollbar whether there is enough content to show or not.

thanks.

+9  A: 

jQuery shouldn't be required. You could try adding the CSS:

body    {overflow-y:scroll;}

This works across the latest browsers, not sure about ie6 though.

laurencek
I believe the `overflow-x`and `overflow-x` have given me some pains in the past.
Júlio Santos
I think this will display the scrollbar only when there is overflow. To display the scrollbar always trybody { overflow-y: scroll; height: 101%;}
Nils Weinander
You have this round the wrong way. If you set the overflow:auto then the scroll bars show if necessary. overflow:scroll always shows the scrollbars. If the content isn't long enough then the scrollbars are greyed out.
laurencek
+3  A: 

Just use CSS.

body {
  overflow: scroll;
}
Júlio Santos
+1  A: 

http://www.w3schools.com/jsref/prop_style_overflow.asp

set overflow property of a containing div to "scroll"

jambox
A: 

try calling a function on the onload method of your body tag and in that function change the style of body like this document.body.style.overflow = 'scroll'; also you might need to set the width of your html as this will show horizontal scroll bars as well

your html file will look something like this

<script language="javascript">
    function showscroll() {
        document.body.style.overflow = 'scroll';
    }
</script>
</head>
<body onload="showscroll()">
megha