Results 1 to 10 of 10

Thread: Where am I on the page?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671

    Where am I on the page?

    Some of the pages on my site are dynamically generated and may be quite long.

    It occurred to me that if I put something similar to below on the bottom of my page I could check whether the page extended below the bottom of the Client's screen and provide a link to the top if it did.

    VB Code:
    1. <P id=BenchMark name=BenchMark></P>
    2. <SCRIPT LANGUAGE=javascript>
    3. <!--
    4. if (window.BenchMark.style.top>screen.availHeight)
    5. {window.document.write("<A href='javascript: void(0)' onclick='return window.scrollTo(0,0)'>Go To Top</A>")}
    6. //-->
    7. </SCRIPT>

    Unfortunately however window.BenchMark.style.top just returns a blank string.

    Can anyone else think of a way of doing this client side?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    OK I have now given up on the above idea and am using this instead.

    VB Code:
    1. <SCRIPT LANGUAGE=javascript>
    2. <!--
    3. var oApp = navigator.appName;
    4.  
    5. var ie = (oApp.indexOf("Microsoft")!=-1);
    6.  
    7. if (ie){
    8. if (document.body.scrollHeight>screen.availHeight)
    9. {window.document.write("<A href='javascript: void(0)' onclick='return window.scrollTo(0,0)'>Go To Top</A>")}
    10. }
    11. else{
    12. if (window.document.body.offsetHeight>screen.availHeight)
    13. {window.document.write("<A href='javascript: void(0)' onclick='return window.scrollTo(0,0)'>Go To Top</A>")}
    14. }
    15. </SCRIPT>

    Unfortunately it doesn't work on Netscape 4 any ideas?

  3. #3
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    *shudder* I give up. Can someone give me a JavaScript manual. I really need to know why people write pages like this.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  4. #4
    scoutt
    Guest
    try what is in bold

    VB Code:
    1. <SCRIPT LANGUAGE=javascript>
    2. <!--
    3. var oApp = navigator.appName;
    4.  
    5. var ie = (oApp.indexOf("Microsoft")!=-1);
    6.  
    7. if (ie){
    8. if (document.body.scrollHeight>screen.availHeight)
    9. {window.document.write("<A href='javascript: void(0)' onclick='return window.scrollTo(0,0)'>Go To Top</A>")}
    10. }
    11. else{
    12. if (window.document.body.offsetHeight>screen.availHeight)
    13. {window.document.[b]writeln[/b]("<A href='javascript: void(0)' onclick='return window.scrollTo(0,0)'>Go To Top</A>")}
    14. }
    15. </SCRIPT>

  5. #5
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Uhm, the page may be severly broken, Scoutt, but that isn't it. document.writeln() appends a newline where document.write() doesn't. Since new lines do not matter....
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    Hmm, it appears from http://developer.irt.org/script/1400.htm that I would need to stick it all into a layer which isn't really suitable for me so looks like NS 4.0 users are just going to have to scroll to the top manually.

    Scoutt thank you very much for your help.

    CiberTHuG - What possible objection can you have to people displaying a Scroll to Top hyperlink when the page is longer than the screen?

    Is it the principle or do you think my solution is badly coded?

    If the latter please put up or shut up!

  7. #7
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Putting up:

    ECMA-262
    getElementById()
    document is not part of window
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    You're right of course but I am not getting any problems with Level 1 DOM browsers.

    My problem is with netscape 4.0 which as far as I know has never heard of getElementById()

  9. #9
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    True that.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  10. #10
    scoutt
    Guest
    Sorry I wasn't much of help. I pretty much guessed at that. it looked good though.

    I haven't studied javascript or even worite my own. so I am not that versed in it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width