This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make a "back to top" feature?