We help IT Professionals succeed at work.

Reloading a parent window from a child.

mor4eus
mor4eus asked
on
I have an iframe in a document which loads a dynamic coldfusion page.  From that page I open child windows
to enter and change data.  What I need is that when you hit submit on the child, it sends the data to
the server, closes the child and reloads the iframe in the parent window.  Is this possible.

Here is my first page.  It has a reload on it to test.

<html><head>
<script>
function doIt(_v)
    {
      if (_v==1)
           {
        document.all.myiframe.src="test2.cfm";
           }
    }
</script>
</head>
<body>
<a href="javascript:doIt(1)">Reload</a><BR>
<iframe name="myiframe" border="1" width=250 height=150 src="test2.cfm"></iframe>
</body></html>


--------My test2.cfm page-----------

<cfquery name="james" datasource="FMRBA">
SELECT * FROM test
</cfquery>
<html
<body>
<table border="1">
<cfoutput query="james">
<tr><td><a ref="" onClick="window.open('changetest.cfm?DocID=#DocID#','mywindow','width=400,height=200',1)">#DocID#</a></td><td>#Desc#</td></tr>
</cfoutput>
</table>
</body>
</html>

------My changetest.cfm-------

Is just a form which sends it's data to updatetest.cfm.

------updatetest.cfm-------

<html><head>
<cfquery name="update" datasource="fmrba">
UPDATE test
set [desc]='#desc#' where docid = '#docid#'
</cfquery>
</head>
<body onLoad="setTimeout(window.close, 1000)" onClose="main.reload()">
</body>
</html>

I know that the main.reload is incorrect, but that is why I am here.
Comment
Watch Question

Commented:
To access the IFRAME that opened the popup window, you may use self.opener window object. Therefore, you can rewrite your code as onClose="self.opener.reload()"

In more complex scenarios, you can use something like

self.opener.top.myiframe instead.

Author

Commented:
I have tried similar things, but I just can't get it to work.  It just wont reload.  It closes the window but then nothing happens.

Author

Commented:
There is a sample here is you want to have a look.

http://reports.fmrecords.com.au/test/test.cfm

Commented:
Your problem seems to be that opener no longer exists when the pop-up window is reloaded as a result of form submit.

I would work around this trouble by causing update button on your popup window call javascript:

opener.document.update_form.docid.value = document.forms[0].docid.value;
opener.document.update_form.desc.value = document.forms[0].desc.value;
opener.document.update_form.submit();
self.close();

and add a hidden form to the iframe:

<form action="updatetest2.cfm">
<input type="hidden" name="docid">
<input type="hidden" name="desc">
</form>

What will happen - the iframe will refresh itself in a most regular manner, and the popup window will close itself cleanly.

Note an additional advantage - you ge rid of one extra .cfm!

Author

Commented:
Ok have tried that, but my javascript is not so good.  I have updated the site in the link.  Thanks so far, but I need a little more help doing this.

Commented:
Yes, I forgot to name the form on the iframe. Sorry. Please change the function buttonup() as follows:

{
opener.document.forms[0].docid.value = document.forms[0].docid.value;
opener.document.forms[0].desc.value = document.forms[0].desc.value;
opener.document.forms[0].submit();
self.close();
}

Author

Commented:
ok, not sure what it does but check out the link.  It closes both windows, the one in the iframe ro something.  Hard to see.  Thanks though.

Commented:

Commented:

Commented:

Commented:

Commented:

Author

Commented:
Hey alexcohn, no text appearing.
Commented:
I know. there was some trouble with EE service.

You didn't change updatetest.cfm. It should simply show the table again (I am not 100% sure about the following, I haven't got a ColdFusion server to try it now):

<html><head>
<cfquery name="update" datasource="fmrba">
UPDATE test
set [desc]='#desc#' where docid = '#docid#'
</cfquery>
<cfquery name="james" datasource="FMRBA">
SELECT * FROM test
</cfquery>
</head>
<body>
<table border="1">
<cfoutput query="james">
<tr><td><a ref="" onClick="window.open('changetest.cfm?DocID=#DocID#','mywindow','width=400,height=200',1)">#DocID#</a></td><td>#Desc#</td></tr>
</cfoutput>
</table>
</body>
</html>

Author

Commented:
Lovely, works fine now.  Thanks for all your help.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.