javascript 如何在浏览页面时保持音频播放?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9555250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to keep audio playing while navigating through pages?
提问by SkinnyBill
I am making a website for my friends band. I would like to know if its possible (apart from using Ajax) to keep audio playing after clicking on a link to another page on the site?
我正在为我的朋友乐队制作一个网站。我想知道是否有可能(除了使用 Ajax 之外)在点击站点上另一个页面的链接后继续播放音频?
I currently have it set up using Ajax to reload the content, but I am having a few issues with it, and I'd rather not deal with the bother unless I really have to.
我目前使用 Ajax 设置它来重新加载内容,但是我遇到了一些问题,除非我真的必须这样做,否则我宁愿不处理这些麻烦。
If not possible, is there a way to minimise the disruption (pausing then playing again) while navigating? It would be possible for the new page to continue playing the track from where the last page stopped, but I would like to minimise the pause. Or, on this subject, is it possible to keep certain page elements loaded after changing the URL (without using # urls), like facebook does (as in, you click on it, but the banner never disappears during loading)
如果不可能,有没有办法在导航时最大程度地减少中断(暂停然后再次播放)?新页面可以从上一页停止的地方继续播放曲目,但我想尽量减少暂停。或者,在这个主题上,是否有可能在更改 URL 后保持加载某些页面元素(不使用 # urls),就像 facebook 所做的那样(例如,你点击它,但横幅在加载过程中永远不会消失)
Thanks for any help :)
谢谢你的帮助 :)
回答by Marat Tanalin
Use Ajaxto load content and History API's pushState()
to alter URL without page reload.
使用Ajax加载内容,使用 History APIpushState()
更改 URL,无需重新加载页面。
For consistent behavior across browsers, consider using a wrapper library like History.js.
为了跨浏览器保持一致的行为,请考虑使用像History.js这样的包装库。
回答by Wesley
Sites like Facebook use JavaScript/AJAX for these kind of things. If you don't want to use it, you can use frames (not recommended). Divide the page in two frames: the player and the website itself. This way you can easily turn it off too, just open the site without frames.
像 Facebook 这样的网站使用 JavaScript/AJAX 来处理这些事情。如果你不想使用它,你可以使用框架(不推荐)。将页面分为两帧:播放器和网站本身。通过这种方式,您也可以轻松地将其关闭,只需打开没有框架的站点即可。
Good luck!
祝你好运!
回答by m02ph3u5
Of course you could also pop up the player in another window/tab. (For now) It won't be possible without frames or javascript.
当然,您也可以在另一个窗口/选项卡中弹出播放器。(目前)没有框架或 javascript 是不可能的。
回答by Dave
It might be troublesome to implement it differently than via AJAX, however you can either use IFrames, where the music would be played in the main one and the content is displayed in the child on or you can always make it a Flash webpage.
与通过 AJAX 不同地实现它可能会很麻烦,但是您可以使用 IFrames,其中音乐将在主页面中播放,内容显示在子页面中,或者您始终可以将其设为 Flash 网页。
回答by IanB
Build it in Wordpress and use the AnythingSlider plugin to have the pages shift within the main page. This way you can have tabbed navigation and never leave the actual page. No need to write too much code. The AnythingSlider uses html for the slides.
在 Wordpress 中构建它并使用 AnythingSlider 插件让页面在主页面内移动。通过这种方式,您可以使用选项卡式导航,而永远不会离开实际页面。无需编写太多代码。EverythingSlider 使用 html 来制作幻灯片。
You can also not use wordpress and just use the AnythingSlider code.
您也可以不使用 wordpress 而只使用 AnythingSlider 代码。
http://css-tricks.com/anythingslider-jquery-plugin/
http://css-tricks.com/anythingslider-jquery-plugin/
and
和
http://wordpress.org/extend/plugins/anythingslider-for-wordpress/
http://wordpress.org/extend/plugins/anythingslider-for-wordpress/
and
和