What is the best way to empty the content on an IFrame
I am wondering what would be the best way to empty the content of an IFrame. The iframe contains an HTML document that comes from another domain. The HTML document may contain videos with voice. At times I am required to open that document in a new window. In case of videos it is very important that I first turn off the video playback so that the user does not get upset by the playback of multiple audio. Now that the document is from another domain, I cannot do a swfobject.stopVideo()
and ther开发者_JS百科efore I do a iframe.contentWindow.location = 'about:blank'
. Is this a good method.
Ideally i want to do a iframe.contentDocument.write("<p>Close the popup window to resume playback.</p>");
. How to detect whether that window was closed is another question, for which I do not have an answer yet (i'd give bonus points but that's not possible on SO).
It sounds like you simply need to replace the iframe src with a page on your server that holds the "in case you're wondering what happened, the video is now playing in the popup window" text. While about:blank should work to clear the frame I would suggest the following:
iframe.src = 'now_playing_in_popup.html';
That will accomplish both clearing it and displaying your message. And as far as monitoring the other window for closing I think that was answered above by ninjagecko.
If you want to give a message in a popup window, you could put a message besides your iframe as a separate sibling element, displaying like a caption below the video.
Since you can control the content of the window (for example, perhaps the popup loads yourwebsite/popupPlayer.html which contains an iframe), you could perhaps add a window.onunload trigger that communicates back to the main page.
Alternatively, you could do (less elegant but more quick to code) var myWin = open('...'); then periodically check the myWin.closed property.
Note that some browsers have popup blockers which may interact weirdly with what you're doing.
精彩评论