It's a jQuery plugin that lets manage the browser history using history.pushState (HTML5) and cross-browser compatibility (including IE6).
http://fiddle.jshell.net/yeikos/rcZWb/show/light
v1.1.0 - 20/07/13
-
New methods:
url,type. -
New event:
pushed. -
Bug fix in
loadevent.
v1.0.1 - 07/05/13
- Bug fix in
loadevent.
v1.0.0 - 28/01/13
- Initial version.
<!DOCTYPE html><html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/yeikos/jquery.history/jquery.history.js"></script>
<script>
$(function() {
$.history.on('load change push pushed', function(event, url, type) {
alert(event.type + ': ' + url);
}).listen('hash');
$('body').on('click', 'a', function(event) {
$.history.push($(this).attr('href'));
event.preventDefault();
});
$('button').click(function() {
location.reload();
});
});
</script>
</head>
<body>
<ul>
<li><a href="/one">one</a></li>
<li><a href="/two">two</a></li>
<li><a href="/three">three</a></li>
<li><a href="/four">four</a></li>
</ul>
<button>refresh</button>
</body>
</html>
load
Fired when the listen is started.
push
Fired before
jQuery.history.pushis called (it can be prevented).
pushed
Fired after
jQuery.history.pushis called.
change
Fired when it happens a change in browser history (back, forward, go).
All events are trigger passing two arguments (address, listen type).
jQuery.history.push(address)
address: string.
Add a new address to history (first it is needed call to
listen).
returns jQuery.history.
jQuery.history.listen()
Starts a automatic listening in base to browser support and in this order: pathname, hash or hash interval.
returns jQuery.history.
jQuery.history.listen('pathname')
Starts a listening using
pathname(pushState).
returns jQuery.history.
jQuery.history.listen('hash')
Starts a listening using
hash(onhaschange). If browser doesn't supports it, then it will use a emulation (hash interval).
returns jQuery.history.
jQuery.history.listen('hash', interval)
interval: interval delay (number). If interval is true, it will convert to jQuery.history.config.interval.
Starts a listening using an emulation (hash interval).
returns jQuery.history.
jQuery.history.unlisten()
Undoes all changes done by
jQuery.history.listen.
returns jQuery.history.
jQuery.history.url()
Get the current URL.
returns string.
jQuery.history.type()
Get the current listening type (hash, pathname or null).
returns string or null.
jQuery.history.on
returns jQuery.history.
jQuery.history.off
returns jQuery.history.
jQuery.history.trigger
returns jQuery.history.