jQuery slide show update url with hash
I've seen a few sites that update the URL with a hash and ID so that you can direct link to JavaScript'd-in content.
I've 开发者_如何学Pythonbeen googling for a bit trying to find a definite resource and havn't found one. Any recommendations?
This site has the behavior I'm looking for:
http://www.davehillphoto.com/bw2/#2
Well you can always make it yourself, here a plugin that creates an event that listens to any change in the URL-hash.
http://benalman.com/projects/jquery-hashchange-plugin/
You can call on the hash in your code using Javascript. window.location.hash
, if you write this to a variable you can write a function to do whatever you want with the hash.
here is a simple example that alerts the hash value, whatever it currently is.
HTML
<button type="button" onclick="getHash()">Click Me</button>
JS
function getHash() {
var hash = window.location.hash;
alert(hash); // alerts the hash tag at the end of the URL
}
LIVE DEMO
(change the hash at the end of the url in the address bar, and it will alert whatever you enter into the address bar after the Hash symbol, including the hash).
精彩评论