相关疑难解决方法(0)

窗口绑定POPSTATE

鉴于以下内容:

$(window).bind("popstate", function() {
    alert('popstate');
});
Run Code Online (Sandbox Code Playgroud)

首次加载时,警报会触发FireFox和Chrome,但不会触发Safari.这是为什么?其他人看过这个并知道如何最好地解决这个问题?

javascript jquery html5 history

29
推荐指数
3
解决办法
4万
查看次数

popstate返回event.state未定义

我正在学习HTML5中的历史,在这个例子中(打开JavaScript浏览器控制台以查看错误)event.state.url返回:

Uncaught TypeError: Cannot read property 'url' of undefined
Run Code Online (Sandbox Code Playgroud)

看看和帮助:http://jsfiddle.net/un4Xk/

jquery html5 history pushstate

25
推荐指数
1
解决办法
2万
查看次数

使用History API pushState设置后获取历史状态对象

如何获取我使用HTML5 History API设置的状态对象:

var stateObj = { foo: "bar" };
history.pushState(stateObj, null, url);
Run Code Online (Sandbox Code Playgroud)

我在尝试:

$(window).bind('popstate', function(event) {
    alert(event.state);
});
Run Code Online (Sandbox Code Playgroud)

它回来了undefined.

谢谢!

javascript jquery html5

5
推荐指数
2
解决办法
8136
查看次数

后退按钮只能使用一次

我正在我的页面上工作,但找不到我的问题的答案。

我正在使用 window.history.pushstate 和 onpopstate 事件,这是我的代码:

changeContent = function(href) {
  window.history.pushState({}, '', href);
  if (href == "/") {
    $('#main').load('main.html');
  } else {
    $('#main').html('<iframe id="gallery" src="photos'+href+'/index.html"></iframe>');
  }
};

$(window).on("popstate", function(e) {
  changeContent(location.pathname);
});

$(document).on("click", ".galleryLink", function() {
  var href = $( this ).attr( "href" );
  changeContent(href)
  return false;
});
Run Code Online (Sandbox Code Playgroud)

IE

谷歌页面 -> 我的主页 -> 图库 -> 后退按钮 -> 我的主页 -> 后退按钮 -> 我的主页 -> 后退按钮 -> 我的主页

这是怎么回事?

javascript jquery back-button pushstate

4
推荐指数
1
解决办法
1885
查看次数

标签 统计

jquery ×4

html5 ×3

javascript ×3

history ×2

pushstate ×2

back-button ×1