jQuery.hash()

A jQuery plugin that saves strings to document.location.hash and gets them back for you.

Usage

Set variables:

$.hash('foo',42);       //sets the hash to #foo=42 (returns 42)
$.hash('bar','asdf');   //sets the hash to #foo=42&bar=asdf (returns 'asdf')
$.hash('bar','qwerty'); //sets the hash to #foo=42&bar=qwerty (returns 'qwerty') 

Get variables:

$.hash('foo');          //returns '42'
$.hash('bar');          //returns 'qwerty'
$.hash('doesntexist');  //returns undefined 

Download

samhash.js | demo.htm

Demo

Tested in

  • Firefox 3.5 on Debian Linux
  • Chrome 14 on Debian Linux
  • Opera 11 on Debian Linux
  • Internet Explorer 6 on Windows XP
  • Internet Explorer 9 on Windows 7


CC0 To the extent possible under law, has waived all copyright and related or neighboring rights to this work. This work is published from: New Zealand.