原则上不同的页面,资源重新加载,音乐的播放会被重置。
要实现音乐的连续播放,可以尝试使用如下的一些方法:
1. 主页面使用frame,
实际上是隐藏了music.html,只显示index.html,然后页面切换只是在index.html所在的那个frame发生,而主页面和music页面实际未重新加载。
这样音乐可以连续播放,但缺点是没办法在index.html页面中控制音频播放。
2. 使用Ajax动态加载非音乐部分的页面,使用HTML5 history API来控制浏览器的前后跳转。
history.pushState(null,null,link.href);在按下浏览器回退时,触发popState事件,
window.addEventListener("popstate",function(e){//loadPreviousPage();}
参考链接:
1. http://stackoverflow.com/questions/13928994/continuing-music-playback-even-while-changing-pages
2. http://html5demos.com/history