Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Trying to load iframe from another iframe

    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.
    Code:

    Code:
    function updateWindow() {
    window.frames[fr2].location = url;
    } 
    window.onload = updateWindow;
    But this doesn't seem to be working. What am I doing wrong here?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,027
    Thanks
    79
    Thanked 4,437 Times in 4,402 Posts
    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
    Code:
        parent.window.frames[fr2].location = url;
    Remember "window" alone refers to the *current* window, whether the main window or an IFRAME's window.

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    this is the code that was set back to my hidden iframe;

    Code:
    <script type='text/javascript'>
        function updateWindow() {parent.window.frames[brm].location = 'http://mybox/reloadtest.htm';} window.onload = updateWindow;
        </script>	
    </head>
    <body>
        <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?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,027
    Thanks
    79
    Thanked 4,437 Times in 4,402 Posts
    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?

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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) ?

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yah you are going to have to put in a local VAR. Then when you call the function you can use your VAR.

  • #7
    New Coder
    Join Date
    Apr 2004
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I put the brm in single quotes and that got it working. Thanks a lot for your help!

  • #8
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You welcome!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •