V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
FinalDream
V2EX  ›  编程

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

  •  
  •   FinalDream · Dec 7, 2013 · 10343 views
    This topic created in 4527 days ago, the information mentioned may be changed or developed.
    6 replies    1970-01-01 08:00:00 +08:00
    sodatea
        2
    sodatea  
       Dec 8, 2013
    一般而言用 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
        3
    kevinzhow  
       Dec 8, 2013
    @sodatea 我猜是放iframe里的~
    Air_Mu
        4
    Air_Mu  
       Dec 8, 2013
    抄袭Soundcloud的。
    ccbikai
        5
    ccbikai  
    PRO
       Dec 8, 2013 via Android
    @Air_Mu 抄袭还算不上,用了相同的技术而已吧
    kongruxi
        6
    kongruxi  
       Dec 8, 2013
    如果一开始用像 Angular 或者 Ember 这些 Single Page Application 的框架,就不必用 iframe 这么奇怪的东西,更不用像虾米那样要在新窗口打开,看看这里 https://hepaimusic.com
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2527 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 06:37 · PVG 14:37 · LAX 23:37 · JFK 02:37
    ♥ Do have faith in what you're doing.