History.js a plugin that can change the address of a browser bar without a refresh (not dependent on jquery)

Source: Internet
Author: User

Example: http://browserstate.github.io/history.js/demo/Introduction HTML4 has some support for the forward and backward API for browsing history such as:
Window.history.back ();
Window.history.forward ();
Window.history.go (-1);
Window.history.go (1);
HTML5 Browser has added a new API that does not refresh the URL address:
var currentstate = history.state;
var stateobj = {foo: "Bar"};
Window.history.pushState (Stateobj, "Page 2", "bar.html");
These APIs are very helpful to build a single page without refreshing the site, but unfortunately they are not available in the old browser.  History.js can solve this problem. History.js gracefully supports the history/state API (pushstate,replacestate,onpopstate) for all browsers. including data, Title,replacestate. Support Jquery,mootools and prototype. In the HTML5 browser, it uses native APIs and can directly modify the URL without having to use the hash value. For HTML4 browsers, the hash value is used for compatibility.
code example

(function (window,undefined) {    //Bind to StateChange Event    History.Adapter.bind (window, ' StateChange ', function () {//Note:we is using StateChange instead of Popstate        var state = History.getstate ();//Note:we is Usin G History.getstate () instead of Event.state    });    Change our states    History.pushstate ({state:1}, ' State 1 ', '? state=1 ');//logs {state:1}, "State 1", "? state=1" 
   
    history.pushstate ({state:2}, "State 2", "? state=2"); Logs {state:2}, "State 2", ". state=2"    history.replacestate ({state:3}, "State 3", "? state=3");//logs {state:3}, "S  Tate 3 ","? state=3 "    history.pushstate (null, NULL,"? state=4 ");//Logs {}, ', '? state=4 '    history.back ();//Logs {State:3}, ' State 3 ', '? state=3 '    history.back ();//logs {state:1}, "State 1", "? state=1"    history.back ();//Lo GS {}, "Home page", "?"    History.go (2); Logs {State:3}, "State 3", "? State=3"}) (window);
   

effect when in HTML5 browser the address bar changes
Www.mysite.comwww.mysite.com/?state=1www.mysite.com/?state=2www.mysite.com/?state=3www.mysite.com/?state= 4www.mysite.com/?state=3www.mysite.com/?state=1www.mysite.comwww.mysite.com/?state=3
Change of Address bar when in HTML4 browser
Www.mysite.comwww.mysite.com/#?state=1&_suid=1www.mysite.com/#?state=2&_suid=2www.mysite.com/#?state=3 &_suid=3www.mysite.com/#?state=4www.mysite.com/#?state=3&_suid=3www.mysite.com/#?state=1&_suid= 1www.mysite.comwww.mysite.com/#?state=3&_suid=3
Project Address: Https://github.com/browserstate/history.js

History.js a plugin that can change the address of a browser bar without a refresh (not dependent on jquery)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.