开发者

History.js + Forms?

开发者_StackOverflow中文版We are migrating from jQuery Ajaxy to History.js. Ajaxy has smart form managment. Does anyone have sample how to integrate History.js to process forms?


History.js is essentially a cross-browser shim that allows you use the HTML5 History API, and it does not specifically provide any built-in form management logic. So if you wanted to use it to manage form states, you would have to manually add history entries to the browser history object like this:

// If the History.js plugin has been included on the page
if(window.History) {

    // Adds a new state and url to the browser history object
    // Eg. If your page was index.html... it becomes index.html?someState
    window.History.pushState(null, $(this).attr("data-href"), "?someState");

}

And if you had some custom logic that you needed to happen when a state change happened, you could do something like this:

// If the History.js plugin has been included on the page

    if(window.History) {

        // Binds to the StateChange Event
        window.History.Adapter.bind(window,'statechange',function() {

            // Do something

        });
    }

For more information on History.js check out the History.js github page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜