Link to home
Start Free TrialLog in
Avatar of mor4eus
mor4eus

asked on

Reloading a parent window from a child.

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.
Avatar of alexcohn
alexcohn
Flag of Israel image

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.
Avatar of mor4eus
mor4eus

ASKER

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.
Avatar of mor4eus

ASKER

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

http://reports.fmrecords.com.au/test/test.cfm
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!
Avatar of mor4eus

ASKER

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.
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();
}
Avatar of mor4eus

ASKER

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.
Avatar of mor4eus

ASKER

Hey alexcohn, no text appearing.
ASKER CERTIFIED SOLUTION
Avatar of alexcohn
alexcohn
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mor4eus

ASKER

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