简体   繁体   中英

why is browser the back button not directing to the last viewed page?

I'm working on a site (reworking is probably a better word as I did not build it originally) and am encountering the following weird scenario:

Users go to a page which shows a list of current events. This is called "whats-on".

I have added a link to this page which takes users to a full event calendar for the month in a typical calendar format. This page is called "event-calendar". Once on the page they can also select which month they want to see and what type of events they are interested in.

Users can click on an event listed in any date to navigate to a page with the event details. (page is event-details with a query that pulls the relevant event.) I have added a back button to the page under the event listing which will return them to the calendar showing the month and search results they just looked at. No issues there - I am using PHP $_SERVER['HTTP_REFERER'] and that works perfectly.

Here is the issue - if I just did a back() or history.go(-1) link on that button, it takes the user all the way back to "whats-on". The same thing happens when you click the browser back button. It just skips over "event-calendar" entirely.

This apparently happens on the site under other scenarios such as business listings and searches.

Obviously I do not want that behavior - I want the back button to go to the previously viewed page like it should!!

I cannot think of anything in the code that would cause this, but the original site developers included a whole bunch of JQuery packages such as jQuery UI, and I'm wondering if something could be interfering with the default back button behavior. Is that even possible??

I guess what I want to know is there is any JQuery code that would change the behavior of the back button so I could hunt it down and kill it!!

Just looking for ideas as to where to start looking.

Apparently the only way I can get it to work is to manipulate the browser history using

    history.pushState({}, '', 'event-calendar?<plus whatever query was used to pull the data>'); 

on the calendar page itself.

This seems to work but what a stupid workaround. Wish I could find the original problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM