admin管理员组

文章数量:1287514

I have a footer section on my website where I want to include a back to Top link. Problem is that it can't detect on which page of the site the user is so it sends it in the index html top. Is there any way to achieve this?

I can't use <a href="#">Back to top</a> since I have a base href that links to the index page of the website.

This code worked well, cross browser too:

<a href="javascript:void(0)" onclick="parent.window.scrollTo(0,0);">TOP</a>

I have a footer section on my website where I want to include a back to Top link. Problem is that it can't detect on which page of the site the user is so it sends it in the index html top. Is there any way to achieve this?

I can't use <a href="#">Back to top</a> since I have a base href that links to the index page of the website.

This code worked well, cross browser too:

<a href="javascript:void(0)" onclick="parent.window.scrollTo(0,0);">TOP</a>
Share Improve this question edited Jan 30, 2013 at 19:01 Tasos asked Oct 23, 2012 at 10:55 TasosTasos 1,6424 gold badges29 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Add a named anchor in your page just before the content, to specify the top of your current page. Like:

<a name="top"></a>
<!-- Rest of your content here -->

Then in your footer, link to the anchor with:

<a href="#top">Back to top</a>

You don't need php for this. Just add a link like this:

<a href="#">Back to top</a>

本文标签: javascriptBack to top link on php included footerStack Overflow