View Full Version : How do you close an IFRAME window?

10-08-2007, 02:54 PM
I have an HTML file that opens a DHTML Window (http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/) ("iframe" content type). The IFRAME has an HTML file with a form in it. After I press OK in the form, I would like to close the DHTML window. But the file in the IFRAME has no knowledge of the dhtmlwindow object in the first file. Ideas? (putting the form code in a "div" content type DHTML Window instead of a "iframe" isn't an option)

Thanks in advance.

10-08-2007, 03:26 PM

var ifr = document.getElementById("theIframe");

10-08-2007, 03:46 PM
If, as I read this, you want to close the iframe from the child page, provided that both the top page and the page in the iframe are on the same domain:

var ifr = parent.document.getElementById("theIframe");

10-08-2007, 03:55 PM
In the dhtmlwindow.js source code there is no ID set for the IFRAME. So just for the sake of it, I went and added id="theIframe" to the code.

jscheur1, your example destroys the IFRAME associated with the dhtmlwindow object, but the DHTML window is still there. All nice and white and blank, but still there.

10-08-2007, 04:03 PM
I've moved this to the DD scripts help section as, you don't really want to know how to close an iframe, although you may or may not want to do that too, just to get the form off of the top page completely.

You want to know how to close the widget. Using the example of the the Google widget from the demo (once again, provided you are on the same domain):

<a href="#" onClick="parent.googlewin.hide(); return false">Hide/close Window</a>

10-08-2007, 05:35 PM
Never mind, I figured it out. I had the variable that contained the widget handle local in scope. Thanks for the help!

BTW, I used the DOM thingy to remove the IFRAME too. But I had to modify the dhtmlwindow.js source code to assign an ID tot he IFRAME tag. It'd be nice to see that in the permanent source code. ;)

t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" id="_iframe-'+t.id+'" name="_iframe-'+t.id+'"></iframe>'

and then when I closed the IFRAME:

var ifr = parent.document.getElementById("_iframe-mywinid");

10-17-2007, 02:36 PM
I am trying to use the window widget to act as a video tooltip popup when user mouses over a button image on my site. The site is: www.copycatdigital.ca/test4.html
I have set it up so that when you mouse over the button the iframe opens with a video embedded in it. When you mouseout, the iframe disappears as it should, but the video keeps playing (Hidden). Is there a way to stop the video as well as hide the iframe?


10-17-2007, 02:40 PM
Pause the video or stop it? To stop the video, you should be able to replace the URL with about:blank like so:

googlewin.onclose = function() { window.frames["_iframe-googlewin"].location.replace("about:blank"); }

where "googlewin" is the name of the window you gave in your call to dhtmlwindow.open()

10-17-2007, 02:54 PM
Thanks for the quick reply. The name of the iframe is homewin, and I want to use onmouseout rather than onclose. Does this make the code different?

Thanks again,