JavaScript doesn't allow you to update window.location
without triggering a reload. While I agree with this policy in principle (it shouldn't be possible to visit my website and have JavaScript change the location bar to read www.yourbankingsite.com
,) I believe that it should be possible to change www.foo.org/index
to www.foo.org/help
.
The only reason I care about this is for bookmarking. I'm working on a photo browser, and when a user is previewing a particular image, I want that image to be the default if they should bookmark that page. For example, if they are viewing foo.org/preview/images0-30
and they click on image #15, that image is expanded to a medium-sized view. If they then bookmark the page, I want the bookmark URL to be foo.org/preview/images0-30/active15
.
Any thoughts, or is there a security barrier on this one as well? I can certainly understand the same policy being applied here, but one can dream.
Sounds like you should check out Really Simple History. It's how Google (for example, Gmail) allows any page to be bookmarkable (and has history) but doesn't refresh the whole page.
As for the other side of things (having people visit your site then automatically popping up the correct image), I'd try checking window.location.hash once the page loads and firing events based on that.
You can add
[Add to Favorites]
button on the page.Sample:
Or use one of these jQuery plugins:
AND / OR
Use URLs with hash at the end and load your content (images etc.) based on that hash value.
There are also lots for jQuery plugins for working with URL hash events, for example:
There are also lots of non jQuery JavaScript libraries for that, for example:
As mentioned, generally with ajaxy sites, you manipulate/check the hash part of the URL (
window.location.hash
) to determine this kind of activity.The biggest issue is making sure to check against the hash in DOM-ready/window-load, as if the user clicked on a given image. This will work with browsers and bookmarks, but may hamper search indexing.
You can add an anchor to the URL without reloading the page and pick that up with javascript:
How about detecting on page load if the URL contains a hash, and if it does, directing them to the page you want them to go to?