不使用 JavaScript 检测用户按下后退按钮?
我知道有一些方法可以判断用户是否使用 Javascript 按下了后退按钮,但是有没有一种方法可以在不诉诸 Javascript 的情况下判断呢?是否有一种解决方案可能只涉及查看引用 URL?
I know there are ways to tell if an user has pressed the back button using Javascript, but is there a way to tell without resorting to Javascript? Is there a solution that involves just looking at referer URLs perhaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有 JavaScript 就不行。
问题是后退按钮不能保证您获得服务器命中。它可以缓存页面客户端,即使它确实命中了服务器(加载页面),那么它也会收到来自初始命中的请求,而不是来自您刚刚所在的页面。后退按钮不会向请求添加“推荐”信息。它只是返回到您所做的最后一件事,而不会发送您刚才所在位置的详细信息。
您需要处理这个客户端。
Without javascript no.
The problem is the back button will not guarantee you get a server hit. It can cache the page client side and even if it did hit the server (loading the page), then it would have the request from the initial hit not like it came from the page you were just on. The back button doesn't add 'referral' information to the request. It just goes back to the last thing you did without sending the details of where you just were.
You need to handle this client side.
是的,这是可能的。这有两个部分 -
因为这是可能的并不意味着您应该使用它。后退按钮是网络的一项基本技术,破坏它会导致可用性较差。
Yes, it is possible. There are two parts to this -
Because it is possible doesn't mean you should use it though. Backbutton is an essential technique for the web, and breaking it is poor usability.