• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 15710
  • Last Modified:

How to get iframe not to cache in IE

Hi

I have a page that contains an iframe. The contents of the iframe are created dynamically, so every time I come to the page containing this iframe I want to force the iframe to refresh. I added these meta tags to the iframe's head:

<META http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT">
<META http-equiv="Last-Modified" content="Sat, 10 Nov 1997 09:08:07 GMT">
<META http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">
<META http-equiv="Pragma" content="no-cache">

and I also add a different random number to the iframe src each time:

<IFRAME SRC="http://www.my_site.com/guide.htm?r=xO9X7hEp2wgW5ZTSB38dCrKQnkyq4MA_" WIDTH=900 HEIGHT=600>

It works in Firefox, but in IE6 it still caches the old page.

Any ideas how to make it work in IE6?

Thanks
tr5
0
tr5
Asked:
tr5
  • 9
  • 6
  • 3
  • +4
1 Solution
 
yeroketCommented:
try
<META HTTP-EQUIV="Expires" CONTENT="-1">
0
 
tr5Author Commented:
Doesn't make any difference.
0
 
nschaferCommented:
Hi tr5,

This is paraphrased from this page: http://www.htmlgoodies.com/beyond/reference/article.php/3472881
and I've also seen this posted in Microsoft Knowledge Base articles although I couldn't tell you which one at this point.  This will cause the page to fail validation. The answer is to add a second <head> setion to the page after the body and add the meta tag for no-cache in both <head> sections

Example:

<HTML>
<HEAD>
<TITLE>---</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</HEAD>
<BODY>

Text in the Browser Window

</BODY>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</HEAD>
</HTML>

Hope this helps,
Neal.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tr5Author Commented:
Tried it. Didn't work. Any other ideas? I'm desperate.
0
 
nschaferCommented:
I'm not sure why that wouldn't work, I've used it many times in the past.  Also adding the random querystring should have worked as well.  Of course I'm assuming you have already deleted the page from your cache before you are trying your tests, but I can't think of anything else to suggest.  Sorry.
0
 
tr5Author Commented:
Do the other meta tags matter?
0
 
nschaferCommented:
Basically different browsers look at different tags for the caching, The one I listed should work in IE.  By adding the additional meta tags it should make things work additional browsers
0
 
arvanhalleorgCommented:
Just curious...the information you have in the iframe, I'll assume is a new page itself. Which is dynamically created. Do you have your <META http-equiv="Pragma" content="no-cache"> on both the main page and page used in the iframe? Not just one page?
0
 
arvanhalleorgCommented:
if that doesn't help you, clear history, close the browser, then reopen the page (still with your meta on the main and iframe pages) and you should be okay.
0
 
tr5Author Commented:
The browser has to stay open. I can't expect my users to do "refresh" in the iframe or close the browser.

I have <META http-equiv="Pragma" content="no-cache"> in both pages.
0
 
arvanhalleorgCommented:
You misunderstand what I mean. You are the developer. It would stand to reason that your browser may have the old history of your page in its cache from when the page did not want to drop it from cache. clear, close, reopen. Your users won't have to worry about this because your old copies of the page arent in their history to begin with.
0
 
tr5Author Commented:
But what happens is that the users go to the iframe, look at it, go back to the previous page, change something, then go forward to the iframe page again and expect to see the new values. But they don't obviously. I tried your suggestion. Even if I clear the history it doesn't work for the scenario I describe.
0
 
arvanhalleorgCommented:
ah from what you say then, it doesn't sound like a cache problem. Sounds more like the information isn't being 'seen'. Could you tell me how the data is being sent to the iframe and how iframe is reading it into view? It reminds me a bit of when you try to select an already selected item in a select object and the onChange won't trigger. If that makes any sense as an analogy.
0
 
tr5Author Commented:
But if I right-click on the iframe and do "refresh", I get the new data.
0
 
arvanhalleorgCommented:
Yeah, but I mean like, to load the original iframe, there was a source for it. When you modify something in your main part of the screen, you could add a line like...

document.getElementById('frameid').src = 'url';

See if something like that could force your iframe to load the page over again?
0
 
arvanhalleorgCommented:
if you just wrote in a textbox you could add onBlur="document.getElementById('frameid').src = 'iframe_page.asp';" to the element itself so when you lose focus of the object it'll load the page
0
 
tr5Author Commented:
Thank you everybody for your suggestions. Nothing worked however.
0
 
LeeKowalkowskiCommented:
I had a similar problem with muliple iframes (just with IE).  IE had a very odd behaviour with it's first IFRAME, I resorted to putting a dummy iframe before all the others, and styling it so it could not be seen.  

However, your problem doesn't sound exactly the same, but you could try dropping a few IFRAMEs into the same page to see if they all behave this way.

Have you got a working example?
0
 
webwillCommented:
I've just overcome a very similar issue with IE6 iframe caching, by alternating between two different source URLs that feed the iframe.  Nothing else I tried seemed to work.

The way my solution worked is basically this...

I have a dynamic webpage with a form on it and an iframe.  By submitting some information into the form, the page is reloaded and the results are saved to a file, which is then displayed in the iframe.  By alternating between two different output files each time the form is submitted, IE sees a completely different iframe source page being requested each time.

The current output filename is stored in a session variable so it tracks nicely for every individual user.  When the form is submitted, I compare the current filename with output file 1.  If it matches then I set the current filename to be output file 2, save the data and then instruct the iframe to load output file 2.

Hope this helps and happy new year!
0
 
tr5Author Commented:
Sounds like an excellent idea. I will try it. Thanks.
0
 
webwillCommented:
Taking my suggestion a step further (this might not be suitable for your application, but just in case it is), you could generate a unique iframe source file upon every page refresh.  Just keep its filename stored in a session variable so that if the same user reloads the page you can delete it, generate a new filename, store the new filename in the session variable and load that into the iframe.

Using something like PHP's time() or microtime() functions should give you a unique filename to use every time.
0
 
tr5Author Commented:
Another good idea. I have to check if it is applicable.
0
 
onemancatCommented:
It sounds like the page content relies on some cookie or session object (via cookie) that is being dropped by IE6 due to lack of P3P compact policy:

http://support.microsoft.com/kb/323752/en-us

If this is the problem, just add a line like this to the IFRAME response object and it should work:

Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 9
  • 6
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now