JavaScript code to let users double-click to move back to the top of the page

Here's some JavaScript code I found today while poking around the net. Embed this JavaScript code in a web page, and a user can simply double-click anywhere on the page to automatically move back to the beginning of the page. Pretty cool idea. Here's the code:

<script language="JavaScript1.2" 
           type="text/javascript">
<!--
function dblclick() 
{ 
  window.scrollTo(0,0) 
}
if (document.layers) 
{ 
  document.captureEvents(ONDBLCLICK); 
}
document.ondblclick=dblclick; 
-->
</script>

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.