开发者

How to keep video playing when going back to previous page in JS

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 prev开发者_如何学Cious 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 ?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜