Browser back button not functioning correctly

Hello,
I’ve written some pages using html and PHP. The code is huge, and if you need further clarification, I’ll post it, but I’ll start by explaining the structure.
There’s an index page containing a menu which calls various subpages, all php scripts.
Once in a subpatge, you get to select from a list of clients/transactions etc. If you select an element, you’re linked to the same page using $_GET with parameters passed in the link. All good so far.
However, I select an element, realise it is the wrong one, and hit the back button. Nothing happens. If I hit the back button again, I’m returned to the indesx page.
This inconsistent behaviour is annoying, especially since I’m going to have to teach non-computerate users how to use it.
I could of course write a back button myself, but I’m intrigued to know why this doesn’t work, and whether there’s a way to make it work. Me and JS aren’t the best of friends, but if I have to use it as part of a solution, I will.
Thanks for any thoughts.

Will the subpage url be visible in the browser header?

If not this may be a common problem with SPA or similar. You have to update the browser history “manually”.

1 Like

Hmm, not sure how to do that.
Thanks.

You need to post an example with enough code that reproducers the problem.

Methinks your desired behavior is probably better handled by javascript and AJAX…

specifically, this part sounds like the browser history part you’re probably tripping over, especially if the ‘element’ youre referring to is form data.

Yes, you’re right, but how do I get around it. Shall I repost in the JS section, not wishing to infringe any rules…

Get around what specifically? So far, the actual problem hasn’t been identified, because no code that reproduces the problem has been posted.

I cannot post the whole coode here. There are many dependencies, and the test site is secure. but being specific, the back button goes wrong when pages like this are posted to history:
www.testpage.com?id=7757 or:
www.testpage.com?id=5656&action=3
The way I tried to handle this was by using the javascript here:
https://codepen.io/Gridman/pen/NWQVJrJ
Launching a page with no parameters seems to work fine, but when parameters have been posted in $_GET, you have to press the back button twice before anything happens. Initially, I call the subpage with no parameters, back works fine. From that subpage, I call the same subpage this time with parameters (see above). Hitting the back button once appears to do nothing. Hitting it a second time takes me back to the index page.
The subpage contains a table with various bits of client information, and within this table, there are buttons which take the user to into the same subpage, but allows them to do various things depending on which button they click. If you pick the wrong client, or hit the wrong button, hitting the back button will eventually take you to the index page missing out the initial subpage.
I hope this is clear?

No reason to have two threads open for the same issue.

Since the description seems to be more straight forward, I’m going to mark this one as closed and redirect everyone to the other thread

THREAD CLOSED