Results 1 to 5 of 5

Thread: How to reload and/or refresh an iframe...

  1. #1
    Join Date
    Jan 2011
    Posts
    51
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default How to reload and/or refresh an iframe...

    Hi all!

    I would like (need) to know wich formula is the correct one to current standards using jquery or javascript to "refresh or update from the cache" an iframe with a link embedded in the iframe itself (and if possible, also how to reload from the web server).

    Thanks in advance for your replies.

    Luys

    P.S.: I suppose some people might be also interested in how making such requests from the parent page, that is, a complete solution with all the four options.
    Last edited by Luys; 08-09-2011 at 01:11 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    To reload from cache, no javascript is required, just an ordinary link pointing to the page. So, say the page in the iframe is called iframe.htm, a link like so on that page will refresh it from cache (assuming the browser has cached it, most will have, assuming it has no headers that require it to reload from the server, if it does, they must be removed for this or any method to work to reload from cache):

    HTML Code:
    <a href="iframe.htm">Refresh From Cache</a>
    From the parent page, you give the iframe a name attribute:

    HTML Code:
    <iframe name="myframe" src="iframe.htm"  . . .   . . .></iframe>
    and the link looks like so (same conditions as above):

    HTML Code:
    <a href="iframe.htm" target="myframe">Refresh Iframe From Cache</a>
    To force a reload from the server, you either do the same thing and have headers on the iframe.htm page that force it to load from the server, or if you want to leave those off so you have a choice as to whether or not to load from the server or cache, you can use javascript to create a link. Place this in the page in the iframe where you want the link to appear:

    Code:
    <script type="text/javascript">
    document.write('<a href="iframe.htm?bust=' + new Date().getTime() + '">Refresh From Server</a>');
    </script>
    Same thing for the parent page, just add the target:

    Code:
    <script type="text/javascript">
    document.write('<a href="iframe.htm?bust=' + new Date().getTime() + '" target="myframe">Refresh Iframe From Server</a>');
    </script>
    These are pretty simplistic examples. They work, but there's not much flexibility. You have to already know what page is in the iframe. From the page in the iframe, that's easy - it's that page. From the parent page, unless there are no other pages that could be in the iframe, that's harder.

    But since you seemed primarily concerned with the page in the iframe, I won't go into the details of getting the page in the iframe from the parent to know which page to refresh. Also, with parent/child pages on different domains, no such communication is allowed.

    I should add that using more sophisticated methods for something like this would require extensive cross browser testing, as the iframe is still non-standard in its implementation across browsers.
    Last edited by jscheuer1; 08-08-2011 at 03:44 PM. Reason: I should add . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2011
    Posts
    51
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default

    Once more, thank you so much, John!

    A truly encyclopedic answer to my questions. It remains for future reference for anyone working with iframes and that is in trouble. "Moltes grącies".
    By the way, if I'm not in mistake for a correct behaviour in your first example the target of the link must be set to self: target="_self". This is my two cents ... ;-)

    Right now I have an issue with an object embedded in a page with jquery tabs with iframes: the second tab is "hidden" at first and when the web document is loaded, IE do not draw this object on the iframe file. I have to update manually the frame to works. I'm looking for a solution that refresh o call to this iframe when one select or click this second tab. A simple way to solve a complex problem.

    Thank you.

    Luys
    Last edited by Luys; 08-09-2011 at 12:59 AM.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Unless a base target has been set for the page, the default target for any link is _self.

    But yes. The target should be _self. If there's a base tag or javascript on the page that sets a different target, then target="_self" must be included in the link. Otherwise, it may be omitted.

    Was there another question in there? Or has this solved it for you?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2011
    Posts
    51
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default

    All is OK.
    I have to do my homework, if I can not get off the hook, I will ask for HELP!!!

    Thank you, John.

    Luys

Bookmarks

Posting Permissions

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