0

我注意到在 soundcloud 之类的网站中,当您单击链接时,页面加载就像它只有 ajax 之类的东西一样,但地址栏中的地址仍然发生变化。

例如,当我在 soundcloud 上探索声音时,单击链接会打开页面,但背景音乐仍在播放。如果是ajax,那么地址栏中的地址如何变化。

我是新手网络开发人员,想学习这项技术!!!

4

3 回答 3

1

查看history.pushState

对 HTML5 友好的浏览器支持名为 pushState/replaceState 的新历史 API,它使 javascript 无需重新加载页面即可控制浏览器历史。在较旧的浏览器中,通常使用诸如 location.hash 之类的功能。

于 2013-05-29T17:04:45.167 回答
0

也许,您应该看看这个http://diveintohtml5.info/history.htmlhttps://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Manipulating_the_browser_history

于 2013-05-29T17:01:21.727 回答
0

看看这个问题的答案https://stackoverflow.com/a/4059844/1558255

在其中,您可以看到window.historyHTML5 中使用的示例,例如 Alfred Nerstu 的回答中的以下内容。

  window.history.pushState('Object', 'Title', '/new-url');

如果您只想更改网址而无法返回

  window.history.replaceState('Object', 'Title', '/another-new-url');

该对象可用于 ajax 导航:

  window.history.pushState({ id: 35 }, 'Viewing item #35', '/item/35');

  window.onpopstate = function (e) {
     var id = e.state.id;
     load_item(id);
  };
于 2013-05-29T17:08:20.163 回答