【问题标题】:How do links work in soundcloud?Soundcloud 中的链接如何工作?
【发布时间】:2013-05-29 16:53:20
【问题描述】:

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

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

我是新手网络开发者,想学习这个技术!!!

【问题讨论】:

    标签: javascript html web


    【解决方案1】:

    查看history.pushState

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

    【讨论】:

      【解决方案2】:
      【解决方案3】:

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

      在其中您可以看到在 HTML5 中使用 window.history 的示例,例如 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);
        };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-29
        • 2013-12-24
        • 2012-09-16
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 2015-03-25
        • 2015-04-21
        相关资源
        最近更新 更多