开发者

Complicated question about javascript history object and cookies

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 开发者_Python百科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?


Instead of using a cookie, you can use the anchor part of your URL, e. g.

www.example.com/mypage.html#panel1,state:xy

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜