PDA

View Full Version : DHTML Window Widget - Execute JS On Parent Page?



MarekSukiennik
05-12-2008, 04:35 PM
1) Script Title:
DHTML Window Widget

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

3) Describe problem:

Is it possible to reach up from the DHTML Window and execute a JS function which is on the parent page?

ddadmin
05-12-2008, 09:06 PM
This is only applicable if you're using the IFRAME mode. Within the DHTML window page, you can call a function within the parent window using something like:


parent.dothis()

where dothis() is the function in the parent window. Same idea with variables as well.

MarekSukiennik
05-12-2008, 09:49 PM
Ah ... I should have guessed. Thanks!

tiiiim
05-14-2008, 08:16 PM
Can this be done the other way round too? As in, click something on the parent page to change a div or form value on the pop-up? So far I'm not having any luck!!

MarekSukiennik
05-14-2008, 08:51 PM
Yes ... presuming you have a VAR that is a hanlde to teh window you can use someting like:

winHandle.contentDoc.getElementById("textbox").value = "Joe";

This works if the window is a MODAL window ... not sure about the regular one.

ddadmin
05-14-2008, 09:16 PM
Can this be done the other way round too? As in, click something on the parent page to change a div or form value on the pop-up? So far I'm not having any luck!!

Of course If you're using the IFRAME mode to open a window, for example:


var mywin=dhtmlwindow.open("pagebox", "iframe", "test.htm", "#1: Contact Info", "width=590px,height=350px,resize=1,scrolling=1,center=1")

The page inside the DHTML window can be accessed using the syntax:


window.frames["_iframe-pagebox"]

Notice the matching ID attributes in red. So for example:


alert(window.frames["_iframe-pagebox"].document.body.innerHTML)

tiiiim
05-14-2008, 09:33 PM
Just like to confirm that the


window.frames["_iframe-uniqueID"]

method works perfectly.

I did have some reservations as I'd read somewhere else that this wouldn't work in Firefox, but it works fine (I'm use FF3 Beta 5, so not sure about the previous versions...)

Thanks!!