How to preserve browser history in a photo gallery like facebook does?
I'm developing a photo gallery that uses ajax. I'm using _escaped_fragment_ (#!) too, it already works but when you use the back and fwd browser buttons the url change (the hash frag开发者_如何学Pythonment) but the image doesn't. I read about the onHashChange event but i wanto to know if there's an automatic way to do this, i mean, if there's a way to preserve the DOM changes in the history just like Facebook does.
I change the hash fragment with:
window.location.hash = "!"+sth
I load ajax content retrieving the hash fragment and using it as index of my photo:
var fragment = window.location.hash.replace("#!","");
if (fragment != ""){
currentItem = fragment;
currentItemBZ = fragment-1;
focused = currentItemBZ;
}
Any help or suggestion will be appreciated
I've used this jQuery plugin in the past to retain back-button and history functionality in an ajax-based application:
http://www.asual.com/jquery/address/
You can register an on change listener, and then change the image in your gallery depending on the new value of the hash.
精彩评论