0
我得到我的歷史API工作,但我試圖實現History.js,但我似乎無法訪問state.data。我想使用state.data中的字符串to9調用相應的函數。雖然我的理念很適合歷史API它不History.js我的代碼位於如下:History.js問題
(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);
我的鏈接是這樣:
<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>
任何幫助將不勝感激。
將嘗試並記錄我的結果 –
確定這仍然不起作用時,我提醒我的state.data我得到的對象對象,而不是一個字符串。我如何讓我的state.data顯示一個字符串而不是一個對象。 –
我得到了這個工作,但與state.title,而不是state.data。看起來state.data仍然因爲某種原因持有一個對象 –