fortes / history.js

[Not Maintained!] HTML5 History APIs for legacy browsers. Implements window.history.pushState(), window.history.replaceState(), and the window.onpopstate event.
172 stars 12 forks source link

This project is not maintained!

The code is here if you want it, but this is not maintained. If you'd like to take over, go ahead and send a pull request. Browsers are modern enough, just ditch the last few that don't support the History API.

history.js

history.js provides an implementation of the HTML5 history API: history.pushState and history.replaceState functions, as well as the window.onpopstate event.

Browsers that already support his event (Chrome & Safari, Firefox 4+) use native implementations, which are able to change the page URL without refreshing the page. Older browsers use location.hash in order to mimic the official behavior.

1214 bytes minified / 588 bytes gzipped

Limitations

Installation

Include the script file in your HTML file:

<!-- Include JSON if you want to support older browsers -->
<script type="text/javascript" src="https://github.com/fortes/history.js/raw/master/json2.js"></script>
<script type="text/javascript" src="https://github.com/fortes/history.js/raw/master/history-min.js"></script>

Usage

Same as the official HTML5 API:

// Switch to the item
window.history.pushState({ id: 35 }, 'Viewing item #35', '/item/35'});

window.onpopstate = function (e) {
  var id = e.state.id;
  load_item(id);
};

Any use allowed in the standard but not supported by this API is considered a bug.

Supported & Tested Browsers

Unsupported / Need to test

TODO