Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make a "back to top" feature?

 
Ziyang Zhang
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a log page and I want to add a back to top feature, so user can go back to the top of the page.
Could somebody tell me how to do this?
Thanks a lot.
Ziyang
 
Marc Kruze
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use anchor tags.

I solved this one by using the following code (may vary according to your requirements; this worked for what I had to do):

//This goes on the header
<script language="JavaScript">
function setFocus(componentId) {
var obj = document.getElementById(componentId);
if (obj != null) {
obj.focus(); }
}
</script>

Then on the onclick attribute make a call to setFocus passing the component ID.

I hope this helps.
 
Jay pratt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways that I know of.
1) use an anchor tag in the page:
Link: <a href="#top">back to top</a>
Anchor tag placed at the top so the browser knows where to go: <a name="top"></a>

2) You can do it with Javascript: window.scrollTo(0,0)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic