有没有办法将处理程序绑定到浏览器历史记录后退按钮?
例如,用户从 example.com/home.html
访问页面 example.com/checkout.html
。我想知道是否有一种方法可以将历史记录分配回诸如 example.com/new_offers.html
之类的内容?
因此,当单击浏览器后退按钮时,用户将被重定向到 new_offers.html
,而不是转到 home.html
我知道这可能听起来很尴尬,但这只是示例和我需要这个的东西有点不同。另外,我需要仅使用 JavaScript 来完成此操作(无需服务器端)。
UPD:我发现询问是否可以将处理程序绑定到浏览器后退按钮(如(jQuery))会更清楚:
$(browser.backButton).click(function(e){ ... } )
For example the user came to the page from example.com/home.html
to the page example.com/checkout.html
. I wonder if there is a way to assign a history back to something like example.com/new_offers.html
?
So, when clicking his browser back button, instead of going to home.html
the user will be redirected to new_offers.html
I know it may sound awkward, but it's just the example and the thing I need this for is a bit different. Also, I need to do this using JavaScript only (nothing server-side).
UPD: I figured out that it'd be clearer to ask whether it's possible to bind a handler to browser back button like (jQuery):
$(browser.backButton).click(function(e){ ... })
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以转到 new_offers,而不是从主页转到结帐页面,它会检查变量
checked_out
。如果checked_out
为 false,则将用户重定向到 checkout,并传递所有表单信息。如果checked_out
为 true,则显示 new_offers 页面。checked_out
将在 checkout 页面设置为 true。这样,如果用户在 checkout 页面点击返回,用户实际上会转到 new_offers 页面。
我不太喜欢这种设计,因为这意味着用户必须快速单击返回两次才能访问以前的网站,但它确实满足了您的目标。
换句话说,您当前的设计是这样做的:
home --> checkout
相反,请执行以下操作:
home --> new_offers --(重定向) --> checkout
以便 new_offers 立即重定向到结帐,除非它看到用户已经结帐。
Instead of going to the checkout page from the home page, you can go to new_offers, which checks a variable
checked_out
. Ifchecked_out
is false, then redirect the user to checkout passing along all the form information. Ifchecked_out
was true, then display the new_offers page.checked_out
will be set to true at the checkout page.In this way, if the user clicks back at the checkout page, the user will actually go to the new_offers page.
I don't like this design very much as it means that a user has to click back twice quickly to get to a previous website, but it does satisfy your goals.
In other words, your current design does this:
home --> checkout
Instead, do this:
home --> new_offers -- (redirect) --> checkout
So that new_offers redirects to checkout immediately unless it sees that the user has already checked out.
由于您已将问题修改为有关 jQuery,因此您可以使用此 jQuery 插件来解决此问题:
http://tkyk.github.com/jquery-history-plugin/
Since you've modified your question to be about jQuery, you can use this jQuery plugin to solve this issue:
http://tkyk.github.com/jquery-history-plugin/
读一下这个。
https://developer.mozilla.org/en/DOM/Manipulated_the_browser_history
Give this a read.
https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history