我得到了我的历史API工作,但我试图实现History.js,但我似乎不能访问state.data。我想在state.data to9中使用该字符串调用相应的函数。虽然我的概念适用于History API,但它不适用于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>任何帮助都将不胜感激。
发布于 2011-11-08 04:06:36
正确的调用方式如下所示...请注意,onclick没有javascript:,并且状态数据被引用!
<a href="#" onclick="History.pushState({state:'newarticles'},'New Articles','newarticle'); return false;">Articles</a>希望这能有所帮助!PEte
https://stackoverflow.com/questions/8041448
复制相似问题