FinalDream
V2EX  ›  编程

网易云音乐播放器不受页面跳转影响是怎么做到的?

  •  
  •   FinalDream · Dec 7, 2013 · 10776 views
    This topic created in 4733 days ago, the information mentioned may be changed or developed.
    6 replies  •  1970-01-01 08:00:00 +08:00
    sodatea
    sodatea
    Dec 8, 2013
    2
    一般而言用 pjax (history.pushState + ajax load, GitHub 就用了这个技术) 可以做到这样的效果. jQuery 有个 pjax 插件(https://github.com/defunkt/jquery-pjax)可以用.
    但是至于网易云音乐……你看一下他的源代码就知道了, 除了播放器都是放在 iframe 里的, 地址部分是通过改变 fragment identifier (# 后的一串字符) 实现的,看了一下代码, http://s3.music.126.net/s/2/pt_index.js 这里也有用到 history.pushState 来保证历史记录能正常使用
    kevinzhow
    kevinzhow
    Dec 8, 2013
    3
    @sodatea 我猜是放iframe里的~
    Air_Mu
    Air_Mu
    Dec 8, 2013
    4
    抄袭Soundcloud的。
    messagebus
    messagebus
    Dec 8, 2013 via Android
    5
    @Air_Mu 抄袭还算不上,用了相同的技术而已吧
    kongruxi
    kongruxi
    Dec 8, 2013
    6
    如果一开始用像 Angular 或者 Ember 这些 Single Page Application 的框架,就不必用 iframe 这么奇怪的东西,更不用像虾米那样要在新窗口打开,看看这里 https://hepaimusic.com
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4341 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 06:00 · PVG 14:00 · LAX 22:00 · JFK 01:00
    ♥ Do have faith in what you're doing.