【发布时间】:2011-11-07 19:24:01
【问题描述】:
我让我的历史 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>
任何帮助将不胜感激。
【问题讨论】:
标签: javascript html history.js