Compatible with webpage caching methods for Iframe frameworks in IE, Firefox, and Google browsers

Source: Internet
Author: User

Advertisement components are often indispensable in our projects. Sometimes we usually choose iframe nested methods for convenient modification. We didn't pay much attention to them at the beginning, in general, it is forced to refresh the advertisement by yourself. After looking at the ip address of the advertisement statistics, I found that many advertisements have been dismounted for half a month, but I still have to click it, that is, the browser caches the content in iframe for loading speed, and many customers simply do not understand force refresh. Therefore, we need to do some operations to prevent caching, we generally choose the method followed by a random number.

The following is a common method on the Internet:

The original Article says this:

Whether it is IE or Firefox, iframe is cached. Many developers may not pay attention to it, steamed Stuffed Bun encountered a similar situation when developing the seckill topic during the flash sale activity of millions of netizens in the shopping capital of Anhui Province. Even if your iframe address is a php dynamic page, browser cache will appear. At the beginning, I thought it would be okay to use the header to prohibit caching on the php page, but it does not seem to work .. .. Let's take a look at the solution to the page cache of the Iframe framework under Firefox. One method we can see from a foreign blog is as follows: HiI 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://lab.wehefei.com/index.php? R = xO9X7hEp2wgW5ZTSB38dCrKQnkyq4MA _ "WIDTH = 900 HEIGHT = 600> It works in Firefox, but in IE6 it still caches the old page. http://lab.wehefei.com amount. Do you understand ??? Hey, fortunately, my computer English is very good. Haha .,.,.. I will not translate ., In Firefox, there are two methods to cache pages in the Iframe framework: 1. Use the above meta header information. Of course, if you use php dynamic pages, you 'd better also send header information, disable caching 2. Add a random number. After html. Haha. We can see that there are two solutions to the iFrame cache problem in IE: (1) the iframe name is randomly changed each time the homepage is refreshed; (2) A random get parameter is assigned to the src path page of iframe each time the homepage is refreshed. For example: <iframe src = "http://www.example.com/thepage.html" name =" aframe "> </iframe> <script type =" text/javascript "> document. frames ["aframe"]. location. href + = (document. frames ["aframe"]. location. href. indexOf ("? ")! =-1? "?": "&") + (New Date (). getTime (); </script>

However,I think this method is too troublesome. I need to distinguish IE from Google.Then write the corresponding implementation methods respectively.

The following is a way to achieve no cache without distinction:

<script type="text/javascript">        document.write('<iframe src="/ad_footer.html?'+ (new Date()).getTime() +'" width="918" scrolling="no" frameborder="0" height="41"></iframe>');</script>

This method has been tested to be effective, and there is no need to distinguish between browsers. OK. I hope it can help you. If there are other simpler methods, you can release them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.