Hash.js - We Stand Behind #
Hash.js is a micro (0.5 KB) JavaScript lib that makes it easy
to manipulate everything that is behind # in the url.
Check out the Github repo at github.com/javve/hash.js and see it in action at PNGTextures.com
Notice : The main focus of Hash.js is simplcity. This is no tool for your super-ajax-native-feeling-app-with-google-bot-support. If
that’s your usage situation, use the awesome History.js .
Usage
Just include hash.min.js or hash.js at your site and then a hash object will become available.
1
2
3
4
5
<script src= "hash.min.js" ></script>
<script>
hash.add({foo: "bar" }); // Url becomes http://url.com#foo=bar
</scrtip>
Methods
hash.add(params)
Add parameter to hash
1
2
3
4
5
hash . add ({ foo : "bar" });
// http://url.com#foo=bar
hash . add ({ car : "dar" , sar : "par" });
// http://url.com#foo=bar&car=dar&sar=par
hash.get(param) or hash.get()
Returns value of paramter in hash. If param is undefined then all values are returned.
1
2
3
4
5
var fooValue = hash . get ( 'foo' );
// fooValue == "bar"
var allValues = hash . get ();
// allValues == { foo: "bar", car: "dar", sar: "par"}
hash.remove(param)
Removes the value with name param.
1
2
hash . remove ( 'foo' );
// http://url.com#car=dar&sar=par
hash.clear()
Clears entire hash.
1
2
hash . clear ();
// http://url.com#
Example
“Those who share get to meet Steve” Book of Jobs 13:37