scrollbar

P

Peter Fastré

Hello

I want to display a link on the bottom of a webpage to go to the top,
but only if the user has to scroll down. If there's a small page, this
link has no use.

I'm using the following code (in the body onload)
var wdb = window.document.body;
var scrolling;

if (wdb.scrollHeight > wdb.clientHeight) {
//alert('Scrolling=True');
document.getElementById('img_totop').style.visibility
= 'visible';
}
else {
//alert('Scrolling=False');
document.getElementById('img_totop').style.visibility
= 'hidden';
}


It works on Internet Explorer, scrollHeight is bigger than clientHeight
with a long page.
But not in firefox, scrollHeight = clientHeight in all cases.
What can I do about it?

regards

Peter
 
M

McKirahan

Peter Fastré said:
Hello

I want to display a link on the bottom of a webpage to go to the top,
but only if the user has to scroll down. If there's a small page, this
link has no use.

I'm using the following code (in the body onload)
var wdb = window.document.body;
var scrolling;

if (wdb.scrollHeight > wdb.clientHeight) {
//alert('Scrolling=True');
document.getElementById('img_totop').style.visibility
= 'visible';
}
else {
//alert('Scrolling=False');
document.getElementById('img_totop').style.visibility
= 'hidden';
}


It works on Internet Explorer, scrollHeight is bigger than clientHeight
with a long page.
But not in firefox, scrollHeight = clientHeight in all cases.
What can I do about it?

regards

Peter
 
M

McKirahan

Peter Fastré said:
Hello

I want to display a link on the bottom of a webpage to go to the top,
but only if the user has to scroll down. If there's a small page, this
link has no use.

I'm using the following code (in the body onload)
var wdb = window.document.body;
var scrolling;

if (wdb.scrollHeight > wdb.clientHeight) {
//alert('Scrolling=True');
document.getElementById('img_totop').style.visibility
= 'visible';
}
else {
//alert('Scrolling=False');
document.getElementById('img_totop').style.visibility
= 'hidden';
}


It works on Internet Explorer, scrollHeight is bigger than clientHeight
with a long page.
But not in firefox, scrollHeight = clientHeight in all cases.
What can I do about it?

regards

Peter


Won't this work for you:

<body>
<a name="top"></a>
..
..
..
..
..
<a href="#top">top</a>
</body>

The link will always show but on a short page it does nothing.
 
P

Peter Fastré

McKirahan said:
Won't this work for you:

<body>
<a name="top"></a>
.
.
.
.
.
<a href="#top">top</a>
</body>

The link will always show but on a short page it does nothing.
I know, but I don't want the link to be shown, it makes no sense if the
page is short.

regards

Peter
 
M

McKirahan

Peter Fastré said:
I know, but I don't want the link to be shown, it makes no sense if the
page is short.

regards

Peter

What dimension (in pixels) is a "short" page?

If the browser window is resized by the visitor
then the page may no longer be "short".
 
P

Peter Fastré

McKirahan said:
What dimension (in pixels) is a "short" page?

If the browser window is resized by the visitor
then the page may no longer be "short".
Short means to me, the page fits on the screen without scrollbars. It
makes no sense showing a top link in this case.
A long page means that the user has to scroll down to read everything,
causing the menu and navigation on top of the page to disappear. Users
want frames-websites, where navigation always stays on top. I have to
convince them not to use frames, and the 'top' link is one of my
arguments to drop the frames.

Regards

Peter
 
M

McKirahan

Peter Fastré said:
Short means to me, the page fits on the screen without scrollbars. It
makes no sense showing a top link in this case.
A long page means that the user has to scroll down to read everything,
causing the menu and navigation on top of the page to disappear. Users
want frames-websites, where navigation always stays on top. I have to
convince them not to use frames, and the 'top' link is one of my
arguments to drop the frames.

Regards

Peter

You didn't address my issue of resizing.

"Users want frames-websites ..." --
are you talking about your Users (or all Users)?

A small "top" image that may not always be applicable
is preferable to the use of scripting that may be disabled.

Another argument against frames is how the print!
 
R

RobB

Peter said:
Hello

I want to display a link on the bottom of a webpage to go to the top,
but only if the user has to scroll down. If there's a small page, this
link has no use.

I'm using the following code (in the body onload)
var wdb = window.document.body;
var scrolling;

if (wdb.scrollHeight > wdb.clientHeight) {
//alert('Scrolling=True');
document.getElementById('img_totop').style.visibility
= 'visible';
}
else {
//alert('Scrolling=False');
document.getElementById('img_totop').style.visibility
= 'hidden';
}


It works on Internet Explorer, scrollHeight is bigger than clientHeight
with a long page.
But not in firefox, scrollHeight = clientHeight in all cases.
What can I do about it?

regards

Peter

This may need some fine-tuning.

window.onload = function()
{
var bShow,
el,
dHt = self.innerHeight ? self.innerHeight :
document.documentElement
&& document.documentElement.clientHeight ?
document.documentElement.clientHeight :
document.body ? document.body.clientHeight : null;
if (dHt && 'undefined' != typeof document.body.scrollHeight)
{
bShow = (document.body.scrollHeight > dHt);
if (document.getElementById
&& (el = document.getElementById('img_t­otop')))
el.style.visibility = bShow ? 'visible' : 'hidden';
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top