JS返回上一页时如何保持视频播放
我有一个页面,其中有一个表,其行是指向其他页面的链接。
当点击一行(链接)时,我将位置设置为该 URL,如下所示:
window.location=mytable.rows[temp_no].getElementsByTagName("a")[0];
在其中一个链接中,视频播放器开始播放链接中的文件,我希望它在我返回时继续播放转到上一页,以便我在浏览其他链接时可以听音乐。
我转到上一页:
window.location.href="..";
这会自然地破坏一切,即视频播放器。我无法弹出新窗口或在新窗口中打开视频播放器,因为此应用程序适用于具有单个浏览器窗口的设备。
有什么解决办法吗?
I have a page that has a table whose rows are links to other pages.
When there is a click on a row (link), I set location to that URL like this:
window.location=mytable.rows[temp_no].getElementsByTagName("a")[0];
And in one of those link, a video player starts to play a file in the link and I want it to keep playing when I go back to the previous page so that I can listen to the music when browsing other links.
I go to the previous page with:
window.location.href="..";
This destroys everything i.e. video player naturally. I can't popup a new window or open video player in a new window since this application works on devices which have single browser window.
Any solutions ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然可以。更改位置会导致整个页面被卸载并加载新页面。
如果您不希望出现此行为,则必须使用 AJAX 来仅重新加载站点的部分内容。
在弹出窗口中打开视频将是另一种解决方案,但新窗口通常很烦人,因此为用户提供“在新窗口中打开视频”链接。
编辑:在这种情况下 - 假设电视浏览器有健全的 JavaScript 引擎 - 使用 AJAX。
另一个“解决方案”是添加一个
onbeforeunload
事件,以在用户离开页面之前请求用户确认。如果不能使用新窗口或 AJAX,这是不可能的,除非您使用框架并在不同的框架中加载另一个页面。
Of course it does. Changing the location causes the full page to be unloaded and the new one to be loaded.
If you do not want this behaviour you'll have to use AJAX to reload only parts of your site.
Opening the video in a popup window would be another solutionbut new windows are usually annoying, so provide the user e.g. with a "open video in new window" link.
Edit: In this case - assuming the TV browsers have sane JavaScript engines - use AJAX.
Another "solution" would be adding an
onbeforeunload
event to request confirmation from the user before he navigates away from the page.Without being able to use a new window or AJAX it is impossible unless you use frames and just load another page in a different frame.
在不同窗口中对视频使用 window.open这样父窗口就可以导航到任何地方。
请记住,您必须禁用所有弹出窗口阻止程序。
** 更新 **
如果您需要同一窗口中的所有内容,请考虑使用一些 iframe 查看其他页面。 iframe 的优点是它们有自己的 CSS 样式、Javascript 沙箱,因此在 iframe 中查看的任何页面(通常)不会影响其父容器。当然,有多种方法可以在 iframe 与其父级之间进行通信,反之亦然。但这不在讨论范围之内。
Use window.open on your videos in a different window so the parent window can navigate wherever.
Keep in mind that you'll have to disable any pop-up blocker.
** UPDATE **
If you need everything in the same window, consider using some iframe to view other pages. The advantage of iframes is that they have their own CSS styles, Javascript sandbox so any page viewed within an iframe does not (generally) affect it's parent container. Of course, there are ways to communicate between an iframe and it's parent and vice versa. But this is out of the question scope.