I got my history API to work however I am trying to implement History.js but I can't seem to access the state.data. I want to use the string in the state.data to9 call the corresponding function. While my concept works well for the History API it doesn't for History.js my code is located below:
(function (window, undefined) {
var History = window.History; // Note: We are using a capital H instead of a lower h
if (!History.enabled) {
// History.js is disabled for this browser.
// This is because we can optionally choose to support HTML4 browsers or not.
return false;
}
// Bind to StateChange Event
History.Adapter.bind(window, 'statechange', function () { // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
alert(State.data);
if (State.data != null) {
var strFun = State.data;
alert(strFun);
//Create the function call from function name and parameter.
var mySplitResult = strFun.split(",");
//var strParam = "null";
//Call the function and arguments
window[mySplitResult[0]](mySplitResult[1], mySplitResult[2]);
}
});
})(window);
My links are as such:
<li>
<a href="#" onclick="javascript:History.pushState({state:newarticles},'New Articles','newarticle'); return false;">Articles</a>
</li>
<li>
<a href="#" onclick="javascript:History.pushState({state:displaybookmarks},'Favourties','favourties'); return false;">Favourites</a>
</li>
<li>
<a href="#" onclick="javascript:History.pushState({state:pagenation},Listing,1,'Archive','archieve1'); return false;">Archive</a>
</li>
Any help will be greatly appreciated.
The correct way to call each is the following... Notice that the onclick doesn't have the javascript:, and the state data is quoted!
<a href="#" onclick="History.pushState({state:'newarticles'},'New Articles','newarticle'); return false;">Articles</a>
Hope that helps! PEte
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.