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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Javascript reload on iframe gets permission denied error

    Trying to use js to reload an iframe so that it can do a query again and show a live update to the given number.

    I'm doing:
    <code>
    <iframe id="ifrm" name="ifrm" onload="ifrm.window.location.reload();" src="url" width="400px" height="100px" scrolling="no" frameborder="0">
    Sorry, your browser doesn't support iframes.
    </iframe>
    </code>

    Any ideas?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    No, that won't work. For starters, only MSIE lets you refer to objects by their id directly, as you are doing.

    Other browsers would require document.getElementById('ifrm')

    But why do either? Just use this to refer to the iframe. After all, the onload method is a method on <iframe>.

    But I don't get why you want the <iframe> to be reloaded as soon as it is loaded. Wouldn't you want to wait a while, for something to change? As it is, you are virtually guaranteed that you will be reloading exactly what was just loaded.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Oh, and the reason you are getting the permission denied error: Apparently the URL in the <iframe> is from a different server than the URL of the main window. So by trying to use JavaScript that runs in the main window to invoke the reload method of the <iframe>, you are doing cross-site scripting, which is disallowed.

    Why not simply change src= of the <iframe>? That you *can* do from the main window.

    e.g., document.getElementById('ifrm').src='http://www.anothersite.com?zzzzz='+Math.random();

    Tacking on the random querystring will force the browser to load the page instead of using a cached copy.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    GraceNZ (03-21-2012)

  • #4
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Old Pendant, you are right about the cross website security issue, there is no way to change content hosted on a different url.


  •  

    Tags for this Thread

    Posting Permissions

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