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
    Jun 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Help refreshing iframe?

    I need help. I'm trying to reload a frame using javascript. None of the code snippets I found on google work! I don't need to change the src, I just need to refresh it, with cookies intact and whatever varibles may have been passed.

    Here's what I'm using:

    Code:
    <script type="text/javascript">
    function myFunc(){
    document.getElementById("p").location.reload(true);
    }
    </script>
    <iframe id="p" src="http://google.com/"></iframe>
    <a onClick="myFunc()">Refresh the frame!</a>
    But it doesn't work! I'm really confused and don't know what to do.
    Last edited by motionman95; 07-26-2009 at 08:29 AM.

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by motionman95 View Post
    I need help. I'm trying to reload a frame using javascript.
    Try:
    Code:
    document.getElementById( "p" ).contentWindow.location.reload( true );

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    An iframe doesn't have a location object- it is just an html element.
    You need to access the window object in the iframe-
    document.getElementById("p").contentWindow may do it.

  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by randomuser773 View Post
    Try:
    Code:
    document.getElementById( "p" ).contentWindow.location.reload( true );
    Doesn't work.

  • #5
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by motionman95 View Post
    Doesn't work.
    What do you mean 'doesn't work'?
    No effect at all?
    No console errors?
    Time to show the whole thing I'd say.

  • #6
    New Coder
    Join Date
    Jun 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I didn't understand what you meant by "console errors" Googled and WALA! It will definitely become a tool in my coding arsenal.

    Here's the error in Console:

    Error: Permission denied for <file://> to get property Location.reload from <http://www.google.com>.
    Source file: file:///C:/test.html
    Line: 4


    And the code is:

    PHP Code:
    <html>
    <
    script>
    function 
    theFunc(){
    document.getElementById"p" ).contentWindow.location.reloadtrue );
    }
    </script>
    <body>
    <iframe id="p" src="http://google.com"></iframe>
    <a onClick="theFunc()>RELOAD FRAME</a>
    </body>
    </html> 

  • #7
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by motionman95 View Post
    <iframe id="p" src="http://google.com"></iframe>
    You're attempting cross-domain scripting, which isn't allowed.

  • Users who have thanked randomuser773 for this post:

    motionman95 (07-26-2009)

  • #8
    New Coder
    Join Date
    Jun 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    So that's why! I think I know how to fix it, then.


  •  

    Posting Permissions

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