scrollbar

Discussion in 'Javascript' started by Peter Fastré, Mar 31, 2005.

  1. 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
    Peter Fastré, Mar 31, 2005
    #1
    1. Advertising

  2. Peter Fastré

    McKirahan Guest

    "Peter Fastré" <> wrote in message
    news:%XS2e.51508$-ops.be...
    > 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
    McKirahan, Mar 31, 2005
    #2
    1. Advertising

  3. Peter Fastré

    McKirahan Guest

    "Peter Fastré" <> wrote in message
    news:%XS2e.51508$-ops.be...
    > 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.
    McKirahan, Mar 31, 2005
    #3
  4. McKirahan wrote:

    >
    > 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
    Peter Fastré, Mar 31, 2005
    #4
  5. Peter Fastré

    McKirahan Guest

    "Peter Fastré" <> wrote in message
    news:rKU2e.51557$-ops.be...
    > McKirahan wrote:
    >
    > >
    > > 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


    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".
    McKirahan, Mar 31, 2005
    #5
  6. McKirahan wrote:

    >
    >
    > 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
    Peter Fastré, Mar 31, 2005
    #6
  7. Peter Fastré

    McKirahan Guest

    "Peter Fastré" <> wrote in message
    news:JgV2e.51571$-ops.be...
    > McKirahan wrote:
    >
    > >
    > >
    > > 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


    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!
    McKirahan, Mar 31, 2005
    #7
  8. Peter Fastré

    RobB Guest

    Peter Fastré wrote:
    > 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';
    }
    }
    RobB, Mar 31, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BestNews
    Replies:
    0
    Views:
    1,171
    BestNews
    Sep 5, 2003
  2. Marco Liedekerken

    Panel with horizontal scrollbar

    Marco Liedekerken, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,906
    Rajesh.V
    Jun 26, 2003
  3. Steve C. Orr, MCSD
    Replies:
    0
    Views:
    803
    Steve C. Orr, MCSD
    Aug 1, 2003
  4. Jeremy Chapman
    Replies:
    1
    Views:
    863
    szabelin
    Aug 15, 2003
  5. Alex

    ScrollBar? Does it exist just WEB ScrollBar Control?

    Alex, Apr 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    249
    Alvin Bruney [MVP]
    Apr 4, 2004
Loading...

Share This Page