Search code examples
javascripthtmlhref

Back to top link on php included footer?


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>

Solution

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

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