How to Back Button with parameters?

My client uses Full Screen (F11) with Chrome and wanted me to add a back button so I added one with

onclick="history.go(-1);"

into an include page (so it’s common to all pages).

image

The issue I have is that there is a page with a very large list, clicking on a ‘business’ takes you to an SPA page via a Route, and when you then press the aforementioned Back button it returns you to the previous list BUT back to the top of the list rather than to the item that was clicked on. Very frustrating when he’s trying to go through the list one-by-one.

Any thoughts on how best to implement a “Back to where I was in the list” type thing?

Maybe add ids to your list items and on click send them to the url:

https://mysite.com/#list-item-123

where #list-item-123 is your list item ID.

Yes, that is the sort of thing I am looking for. Can I populate the back button with something like

$_SERVER['HTTP_REFERER'] + '/#' + {{company_id}}

I am just not quite sure what the right syntax would be.

I can certainly set-up the ID list items (ID=company_id) on the original listing page.

You don’t need this, clicking back will load the #id part.

Not quite sure I get it.

I have set the IDs like this in the listings page

I have set the link in the original list item to

domain.co.uk/admin/business/6/#anchor_6

Which when clicked, takes you to company number 6 as defined by the Route

If I then press the back button which still has

onclick="history.go(-1);"

it goes back to the list page but to the top again.

What should I be doing?

But does it keep the url the same?

domain.co.uk/admin/business/6/#anchor_6

When you click the link on the listings page it goes to the correct page and shows this as the URL

domain.co.uk/admin/business/6/#anchor_6

When you then click the back button it goes back to listings page and shows this as the URL

domain.co.uk/admin/contacts

Ah fine, i see. Maybe just don’t use history.go(-1); on the details page.
Try another thing - from the list page, on click set a session value with the id (instead of url) and then on the details page use a button which goes to the route 'domain.co.uk/admin/contacts/#' + your_session_value so that it redirects back to: domain.co.uk/admin/contacts/#list-item-123

OK, I have changed the back button so when clicked on it goes to

domain.co.uk/admin/contacts/#anchor_31

but it still goes to the top of the page rather than down to anchor_31

image

I have put a text version of the anchor so I can see where it is physically placed.

image

Could it be because it’s dynamic or a repeat or something that I am missing?

Hi Teodor, I have tried your suggestion, and variations of it, to no avail.

I can get anchors to work when the button or link are on the same page as the anchor (destination) but not when going from one page to another.

My thoughts are that when you click on a link from one page to another, when it gets to that target page it has to run whatever Server Connect Components there are, and then by that time it's forgotten about the anchor request - I have no evidence of this :smile:

Current set-up : SPA Pages, Windows 10, MySQL, PHP
Wappler Version : 3.73
Operating System : Windows 10 Pro
phpMyAdmin