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.
Bookmarks