wood burning stoves 2.0*
The moose likes JSF and the fly likes How to make a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "How to make a "back to top" feature?" Watch "How to make a "back to top" feature?" New topic
Author

How to make a "back to top" feature?

Ziyang Zhang
Ranch Hand

Joined: Jul 17, 2010
Posts: 47
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


Enjoy life!
Marc Kruze
Greenhorn

Joined: Oct 28, 2010
Posts: 5
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

Joined: Oct 29, 2010
Posts: 2
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)
 
GeeCON Prague 2014
 
subject: How to make a "back to top" feature?