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('chan getest.cfm ?DocID=#Do cID#','myw indow','wi dth=400,he ight=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.
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=
}
}
</script>
</head>
<body>
<a href="javascript:doIt(1)">
<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('chan
</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.
</body>
</html>
I know that the main.reload is incorrect, but that is why I am here.
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.
ASKER
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_for m.docid.va lue = document.forms[0].docid.va lue;
opener.document.update_for m.desc.val ue = document.forms[0].desc.val ue;
opener.document.update_for m.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!
I would work around this trouble by causing update button on your popup window call javascript:
opener.document.update_for
opener.document.update_for
opener.document.update_for
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!
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].d ocid.value = document.forms[0].docid.va lue;
opener.document.forms[0].d esc.value = document.forms[0].desc.val ue;
opener.document.forms[0].s ubmit();
self.close();
}
{
opener.document.forms[0].d
opener.document.forms[0].d
opener.document.forms[0].s
self.close();
}
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.
ASKER
Hey alexcohn, no text appearing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lovely, works fine now. Thanks for all your help.
In more complex scenarios, you can use something like
self.opener.top.myiframe instead.