简体   繁体   English

为什么浏览器的后退按钮不指向最后浏览的页面?

[英]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. 那里没有问题-我使用的是PHP $ _SERVER ['HTTP_REFERER'],效果很好。

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". 这是问题所在-如果我只是在该按钮上执行了back()或history.go(-1)链接,它将使用户一直回到“操作上”。 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. 我想不出代码中会导致这种情况的任何东西,但是最初的站点开发人员包括了一堆JQuery程序包,例如jQuery UI,并且我想知道是否有什么东西会干扰默认的后退按钮行为。 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!! 我想我想知道的是,有任何JQuery代码都会改变后退按钮的行为,因此我可以追查并杀死它!

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. 希望我能找到原来的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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