如何知道用户是否单击了上一页的后退按钮

时间:2021-09-15 19:00:36

I have a page that will only redirect the user to a certain page depending on some parameters. So this page will always redirect the visitor.

我有一个页面,它只会根据某些参数将用户重定向到某个页面。因此,这个页面将始终重定向访问者。

The problem is when the visitor arrives on this page using the back button. He/She will just be redirected on the page where he/she just clicked the backbutton.

问题是当访问者使用后退按钮到达页面时。他/她将会被重定向到他/她刚刚点击后退按钮的页面上。

The context: Three pages: A, B and C

上下文:三页:A, B和C

On page A i click a link to go to page B. page B will simply redirect me to page C.

在页面A上,我点击一个链接到page B. page B将简单地重定向到C页面。

The Problem: Click back on page C. I go to page B for a few seconds but then i'm redirected back to page C

问题:点击回到C页面,我转到B页面几秒钟,然后转回到C页面。

As it should be: On Page C, I want to go to page A when i click the back button.

应该是这样的:在C页上,我想在单击back按钮时转到A页。

I thought i could use Request.UrlReferrer but this contains the url of page A

我想我可以用请求。UrlReferrer,但是这个包含页面A的url

Is there any cross browser sollution that will let me do this?

有什么跨浏览器的解决办法可以让我这么做吗?

I would prefer a server side sollution, but I'm open for client side too.

我更喜欢服务器端评估,但我也对客户端开放。

EDIT: I just had the idea that it may be possible to replace the entry in the browser history of page B with page A on the moment when the visitor is redirecet to page C. But i don't know if this is possible and allowed.

编辑:我刚刚有个想法,当访问者重定向到c页时,可以用A页代替B页浏览器历史中的条目,但我不知道这是否可能,是否允许。

1 个解决方案

#1


3  

Try this

试试这个

History.js

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

历史。js优雅地支持所有浏览器中的HTML5 History/State api (pushState、replaceState、onPopState)。包括继续支持数据,标题,替换。支持jQuery、MooTools和Prototype。对于HTML5浏览器,这意味着您可以直接修改URL,不再需要使用散列。对于HTML4浏览器,它将恢复使用旧的onhashchange功能。

https://github.com/browserstate/history.js

https://github.com/browserstate/history.js

#1


3  

Try this

试试这个

History.js

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

历史。js优雅地支持所有浏览器中的HTML5 History/State api (pushState、replaceState、onPopState)。包括继续支持数据,标题,替换。支持jQuery、MooTools和Prototype。对于HTML5浏览器,这意味着您可以直接修改URL,不再需要使用散列。对于HTML4浏览器,它将恢复使用旧的onhashchange功能。

https://github.com/browserstate/history.js

https://github.com/browserstate/history.js