PDA

View Full Version : HTML : Hiding IE scroll bar


Schwinnz
15-03-2003, 11:51 PM
Hi !

Is there a way to hide the scroll bar without using frames ?

Little Nicky
16-03-2003, 03:36 AM
Hey Schwinnz

Yes there is a way, and I've written a little script for you to make it work.<html>

<head>
<title>Show Hide Scrollbars</title>
<script name="Detect Browser" language="Javascript">
var detect = navigator.userAgent.toLowerCase();
var browser,thestring;

if (checkIt('msie'))
{
browser = "Internet Explorer";
}
else if (!checkIt('compatible'))
{
browser = "Netscape Navigator";
}
else browser = "An unknown browser";

function checkIt(string)
{
place = detect.indexOf(string) + 1;
thestring = string;
return place;
}
</script>
<script
name="Add and Remove Scroll Bars" language="Javascript">
function noScrollIE()
{
document.body.scroll="no";
}
function scrollIE()
{
document.body.scroll="yes";
}
function noScrollNS()
{
document.width= window.innerWidth;
document.height=window.innerHeight;
}
function scrollNS()
{
document.width=1000;
document.height=1000;
}
</script>
<script "Do the work" language="Javascript">
function removeScrollBars()
{
if (browser = "Internet Explorer")
{
noScrollIE();
}
else if (browser = "Netscape Navigator")
{
noScrollNS();
}
}
</script>
</head>

<body onload="removeScrollBars()">
<a href="javascript:noScrollIE();">IE Scrollbars Off</a><br>
<a href="javascript:scrollIE();">IE Scrollbars On</a><br>
<a href="javascript:noScrollNS();">NS Scrollbars Off</a><br>
<a href="javascript:scrollNS();">NS Scrollbars On</a><br>
</body>

</html>I've put the functions to put the scrollbars back on in case you need them. I've also put some links in the test page so you can test it.

It is a longish script, but it's worth it, because then they get removed for the two major browsers and it is not browser specific (not really anyway).

The Threedy forums seem to put a space between the words "java" and "script" in the <a href> tags ... if they are still there when you have copy/pasted it, just remove the space.

I hope this helps,
Nik

Schwinnz
16-03-2003, 04:12 AM
I found that on the internet in another form but is there a way to automatically hide it ?

Tim_Cutho
16-03-2003, 06:29 AM
what do you mean?


you could just put scroll="no" in your body tag if you're lazy...

Tim_Cutho
16-03-2003, 06:30 AM
and also scroll="auto" if you want it to scroll only when there is too much content to fit on the one screen...

Schwinnz
16-03-2003, 06:37 AM
Thank you, that's what I was looking for. :)

Little Nicky
16-03-2003, 09:43 AM
The one I gave is automatic it just works on both IE and NS if you just put scroll="no" in the body tag then it will only work on IE. It is best to be crossbrowser, but it's your choice of course.

Tim_Cutho
16-03-2003, 10:03 AM
mmm, seems a fair bit off effort to just hide the scrollbar though :roll:

Schwinnz
16-03-2003, 03:51 PM
Oh little nicky I just understood how your script works... I'm so bad at scripting...

Little Nicky
16-03-2003, 09:45 PM
That's alright Schwinnz :).

Tim: Yeah I know it seems a lot and there might be another way to do it, but I have just got into the habit of making everything as crossbrowser as possible :).

Anyway ... some habits are good and some bad ...