views:

32

answers:

1

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?

A: 

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)

Chris Lercher