I have a page that has several in-page links in it, like:
<a href="#link1">In-page Link 1</a>
<a href="#link2">In-page Link 2</a>
<a href="#link3">In-page Link 3</a>
At the bottom of the page I have a 'Back to Previous Page' link:
<a onClick="history.go(-1)">Back to Previous Page</a>
I discovered that if the user clicks one or more of the in-page links, then clicks the 'previous page' link, they are only taken back to the previous section of the current page, not the previous page as intended.
So I need some php that will increment the '-1' in <a onClick="history.go(-1)"> until it finds a page name that does not contain the current page.
For example, if the user's navigation history is this:
www.my-site.com
www.my-site.com/page1.htm
www.my-site.com/page2.htm
www.my-site.com/page2.htm#link1
www.my-site.com/page2.htm#link2
www.my-site.com/page2.htm#link3
Then, on clicking the Previous Page link, 'history.go(-1)' should increment up to 'history.go(-4)' -- the last page name that doesn't contain 'page2.htm', directing the user to /page1.htm.
Can this be done?