关于javascript历史对象和cookie的复杂问题
我有一个带有滑动面板的单页网站,其中一些具有外部链接。理想的行为是,当访问者单击外部链接时,他们会转到该链接。当他们点击后退按钮时,他们会回到原来所在的面板。
到目前为止,我已经通过将状态保存在 cookie 中来实现此目的。
不过,我想知道,当访问者不只是使用后退按钮或来自除 链接到的网站之外的网站时,是否无法忽略 cookie我的网站。我研究了使用history.previous(它似乎存在权限问题)和document.referrer(它似乎无法将“返回”识别为引用者)。
有想法吗?
I have a one-page website with sliding panels, some of which have external links. The desired behavior is that when a visitor clicks an external link, they go to it. When they hit the back button, they come back to the panel they were on.
So far I've got this working by keeping the state saved in a cookie.
I'm wondering, though, if it isn't possible to ignore the cookie when the visitor hasn't just used the back button or is coming from a site other than ones linked to by my site. I looked into using history.previous, which seems to have permissions issues, and document.referrer, which doesn't seem to recognize "going back" as a referrer.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 URL 的锚点部分来代替使用 cookie,例如,
这样,将通过使用后退按钮来恢复 URL,但在使用直接指向 www.example.com/mypage.html 的链接时则不会。
(此技术由 GWT 使用,如其展示中所示,例如:http://gwt.google.com/samples/Showcase/Showcase.html#!CwBasicButton)
Instead of using a cookie, you can use the anchor part of your URL, e. g.
This way, the URL will be restored by using the back button, but not when using a link directly to www.example.com/mypage.html.
(This technique is used by GWT, as demonstrated in their showcase, e. g.: http://gwt.google.com/samples/Showcase/Showcase.html#!CwBasicButton)