Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Top of Page

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Top of Page

    Use this JavaScript to add a "Top of Page" link at the bottom of your page.

    The link will be displayed only if the contents of the page exceeds the size of the browser window, i.e. if the scrollbars appear.

    Code:
    <script language="JavaScript">
    /* Place this script at the bottom of your page */
    
    //////////////////////////////////////////
    //	Top of Page JavaScript		//
    //	By Premshree Pillai		//
    //	http://www.qiksearch.com	//
    //////////////////////////////////////////
    
    /* Message to be displayed */
    var topOfPageMsg='<a href="#" class="top">Top of Page</a>';
    
    var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
    var ns6=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1;
    var ns4=document.layers;
    lC=(ie4)? document.body.scrollHeight : document.height;
    rC=(ie4)? document.body.clientHeight : window.innerHeight-20;
    if(lC>rC) {
    	document.write(topOfPageMsg);
    }
    var agt=navigator.userAgent.toLowerCase();
    function nsReload() { window.location.reload(); }
    function reLoad() {
    	if (ns4&&(agt.indexOf("win")!=-1)) {
    		setTimeout("window.onresize=nsReload", 500);
    	}
    }
    if(ns4) {
    	reLoad();
    }
    else if(ie4) {
    	window.onresize=new Function("window.location.reload()");
    }
    </script>
    See example here: http://www.premshree.resource-locato...op-of-page.htm

    Last edited by premshree; 07-29-2003 at 06:59 PM.

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    OHIO
    Posts
    1,438
    Thanks
    1
    Thanked 0 Times in 0 Posts
    On you example page it only works if you first resize your window, the refresh the page.

    Great idea though because then it only shows up on pages that actually need it.

    Is here a way to change the positioning of where the "Top of page" link comes up? Place it in a div and position it?

    MNS
    [size=1]"If you want to be "in the biz" you are going to have to roll with the changes or get out, basically."

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll have to make changes to this line:

    Code:
    var topOfPageMsg='<a href="#" class="top">Top of Page</a>';

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    It's better for non-NS4 browsers not to reload the page when the window is resized. Just put the "Top of Page" link inside a <div> or <span> tag and just change its display as needed.


  •  

    Posting Permissions

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