1

我对 HTML5 History/history.js 有疑问

我使用History.pushState替换地址栏中的链接。代码:

function setLink() {
var
$this = $(this),
url = $this.attr('data-location'),
title = $this.attr('title')||null;
History.pushState(null,title,url);
}

这适用于所有浏览器。我重新加载了站点,我使用$(window).on('popstate', function() {}检查历史记录中是否存在 pushState。代码:

$(window).on('popstate', function(e) {
e.preventDefault();
var
State = History.getState(),
url = State.url,
relativeUrl = url.replace(rootUrl,'');
id = url.split("/")[4];
alert(url);
alert(id);  
alert("popstate-neu-1");
if (window.history.state !== null) {    
$this = $('#' + id);
setPortfolioIsotopeOpenArgs();
} else {
alert("nothing here");
}
});

这在 Safari(Mac/Win 和 iOS)中完美运行,但在 Firefox 和 IE 中它不起作用。有人有想法吗?

感谢和抱歉我的英语不好。来自奥地利的问候

4

0 回答 0