Advanced go to TOP link
This example shows how to create a advanced "Go to Top" link using JavaScript and HTML anchors...
You will notice that this method will not add a #top to the URL.
<!------> <script type="text/javascript"> function init(){ document.getElementById('gtop').onclick = function(){ window.scrollTo(0,0); return false; } } onload=init; </script> <a name="top"></a> <h1>Top position</h1> <p> A long text ....<br/> A long text ....<br/> A long text ....<br/> A long text ....<br/> A long text ....<br/> A long text ....<br/> </p> <!-- create a long page --> <br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/> <p> Last paragraph. </p> <br/> <br/> <a href="#top" id="gtop">Go to top</a> <br/> <br/>
Author:
Jonas John
License:
Public Domain
Language:
HTML
Created:
05/28/2006
Updated:
05/28/2006
Tags:
tutorials, html, examples
Sorry folks, comments have been deactivated for now due to the large amount of spam.
Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!
Older comments:
<a href='#TOP'>Back to top</a>
changes the URL and therefore the Back button doesn't go to the expected previous page.
<a href='#TOP'>Back to top</a>
No JavaScript or empty anchor tags required.