View Full Version : Trying to load iframe from another iframe

03-03-2009, 05:54 PM
I'm trying to reload a page in an iframe (a content page) from a page in another iframe (hidden, that checks for updates). The parent for both of these iframes is the main window. I'm trying to do this with javascript. The following is the source code that loads into iframe fr1, which is trying to reload iframe fr2.

function updateWindow() {
window.frames[fr2].location = url;
window.onload = updateWindow;

But this doesn't seem to be working. What am I doing wrong here?

Old Pedant
03-03-2009, 10:23 PM
You have to go *UP* from the IFRAME to the parent window.

So *if* that code is running in the hidden IFRAME, you just need to do

parent.window.frames[fr2].location = url;

Remember "window" alone refers to the *current* window, whether the main window or an IFRAME's window.

03-03-2009, 10:54 PM
this is the code that was set back to my hidden iframe;

<script type='text/javascript'>
function updateWindow() {parent.window.frames[brm].location = 'http://mybox/reloadtest.htm';} window.onload = updateWindow;
<form name="form1" method="post" action="repage.aspx" id="form1">

Ok, I changed the code, but the iframe didn't reload. I do have the reload set to a different page (reloadtest.htm) then the original src for that iframe, just to test it. would that have caused it to fail?

Old Pedant
03-03-2009, 10:57 PM
What is the value of the variable brm at that point in the code???

If you haven't assigned it outside of the function, then it's going to be null, so I doubt the code will execute.

Do you have JS debugging enabled? Trapping all JS errors?

03-03-2009, 11:05 PM
brm is the name/id of the iframe. I thought that it would have been a "known" item. I guess I should do var brm = document.getElementById(brm) ?

03-03-2009, 11:42 PM
Yah you are going to have to put in a local VAR. Then when you call the function you can use your VAR.

03-03-2009, 11:43 PM
I put the brm in single quotes and that got it working. Thanks a lot for your help!

03-03-2009, 11:49 PM
You welcome!