Solved

How to get iframe not to cache in IE

Posted on 2006-11-07
26
14,547 Views
Last Modified: 2012-06-21
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
Comment
Question by:tr5
  • 9
  • 6
  • 3
  • +4
26 Comments
 
LVL 4

Expert Comment

by:yeroket
ID: 17888154
try
<META HTTP-EQUIV="Expires" CONTENT="-1">
0
 

Author Comment

by:tr5
ID: 17888320
Doesn't make any difference.
0
 
LVL 19

Expert Comment

by:nschafer
ID: 17889264
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
 

Author Comment

by:tr5
ID: 17889382
Tried it. Didn't work. Any other ideas? I'm desperate.
0
 
LVL 19

Expert Comment

by:nschafer
ID: 17889817
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
 

Author Comment

by:tr5
ID: 17889853
Do the other meta tags matter?
0
 
LVL 19

Expert Comment

by:nschafer
ID: 17890423
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
 
LVL 2

Expert Comment

by:arvanhalleorg
ID: 17891751
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
 
LVL 2

Expert Comment

by:arvanhalleorg
ID: 17891780
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
 

Author Comment

by:tr5
ID: 17892153
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
 
LVL 2

Expert Comment

by:arvanhalleorg
ID: 17892506
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:tr5
ID: 17892579
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
 
LVL 2

Expert Comment

by:arvanhalleorg
ID: 17892714
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
 

Author Comment

by:tr5
ID: 17895920
But if I right-click on the iframe and do "refresh", I get the new data.
0
 
LVL 2

Expert Comment

by:arvanhalleorg
ID: 17897094
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
 
LVL 2

Expert Comment

by:arvanhalleorg
ID: 17897103
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
 

Author Comment

by:tr5
ID: 17930042
Thank you everybody for your suggestions. Nothing worked however.
0
 
LVL 16

Expert Comment

by:LeeKowalkowski
ID: 18180934
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
 
LVL 1

Accepted Solution

by:
webwill earned 500 total points
ID: 18232369
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
 

Author Comment

by:tr5
ID: 18233321
Sounds like an excellent idea. I will try it. Thanks.
0
 
LVL 1

Expert Comment

by:webwill
ID: 18239568
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
 

Author Comment

by:tr5
ID: 18245161
Another good idea. I have to check if it is applicable.
0
 
LVL 6

Expert Comment

by:onemancat
ID: 21764648
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Left menu with a header image 6 35
spacing 5 32
AngularJS / HTML - ng if multiple Date conditions 3 26
SVG Logo 4 20
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now