Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 969
zefs Avatar asked Dec 15 '22 18:12

zefs


2 Answers

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>
like image 198
Oldskool Avatar answered Dec 18 '22 10:12

Oldskool


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

<a href="#">Back to top</a>
like image 43
Alfa3eta Avatar answered Dec 18 '22 10:12

Alfa3eta