How do I add a browser history state?

So I see a lot of people recommend the hidden-iFrame hack that is jQuery history plugin but all I really need is the other half of this technique:

function whenItemIsClicked()
    {
    window.location.hash = this.id;
    //some other stuff, like Ajax
    }

//and then, if page is reloaded...
$(document).ready(function(){
    var loc = window.location.hash;
    //if there happens to be a hash, navigate to corresponding content
    if(loc != '') $(loc).click();
});

Both of these work great. Now, I'd like to attach these two lines

  var loc = window.location.hash;
  if(loc != '') $(loc).click();

to an event, but it seems there isn't one that will be triggered consistently by the back button. Is there a way to add a browser history state that will save the present URL so the above technique will work?

1
задан balupton 18 September 2010 в 11:32
поделиться