View Full Version : Top of Page

07-29-2003, 07:57 PM
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.

<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) {
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) {
else if(ie4) {
window.onresize=new Function("window.location.reload()");

See example here: http://www.premshree.resource-locator.com/javascripts/top-of-page.htm


07-29-2003, 08:08 PM
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?


07-29-2003, 08:10 PM
You'll have to make changes to this line:

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

08-28-2003, 05:02 AM
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.