views:

494

answers:

3

Can anyone tell me how to turn

<a href="javascript:scroll(0,0)"> Top</a>

aka the Top of Page link into a Bookmarklet.

Not very knowledgeable with JavaScript and cannot get this into want I want it to be.

Or if I am using the wrong code, then can you fix it for me and turn it into the bookmarklet.

+6  A: 

Create a bookmark with location:

javascript:void(function(){window.scroll(0,0)}())

Works in Firefox 3 and IE 7.

Mario Menger
There's no reason to use void + an anonymous self invoking function...
J-P
@J-P Except that it doesn't work in IE without it. Give it a whirl.
altCognito
+1 that helped a ton
Maslow
A: 

if u use jquery this link help http://blog.ph-creative.com/post/jQuery-Plugin-Scroll-to-Top.aspx

Haim Evgi
A: 

Another option ...

function scrollUp(){
  var offy;
  if(self.pageYOffset) {
        offy = self.pageYOffset;
  } else if(document.documentElement && document.documentElement.scrollTop){
        offy = document.documentElement.scrollTop;
  } else {
        offy = document.body.scrollTop;
  }

  if(offy <= 0) return;

  window.scrollBy(0, -50);
  setTimeout("scrollUp()", 10);

}

<a href="javascript: scrollUp();">Start Scroller!</a>
João Guilherme