最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

兼容解决 火狐、谷歌 包括IE 、浏览器中 Iframe框架的页面缓存的方法

FEE ajiang-tuzi 5804浏览

我做magento支付插件的时候 遇到一个 Iframe框架的页面缓存 的问题找了半天终于找到决绝办法
浏览器为了加载速度会缓存iframe 里面的内容,而好多客户是根本不懂强制刷新的,那么我们就需要做一些操作不让缓存,我们一般会选择后面加上随机数的方法来做。
下面是网上普遍说的方法:
原文是这么说的:
不管是IE还是火狐浏览器,对于iframe 都是有缓存的,可能很多开发的朋友都没有注意,
即使使你的iframe地址是php动态页面也都会出现浏览器缓存,

一开始,我以为只要在php的页面使用header禁止缓存就OK了,但是貌似不行。。额。。

我们先来看下,火狐下解决Iframe框架的页面缓存的方法,

从国外的一个博客上看到的一个方法,原文如下:

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://lab.weicot.com/index.php?r=xO9X7hEp2wgW5ZTSB38dCrKQnkyq4MA_" WIDTH=900 HEIGHT=600>
 

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

http://lab.weicot.com

额。意思你明白不???嘿嘿,还好,我的计算机英语非常过关,哈哈。,。,。。我不就翻译了。,

很简单的,火狐 中 Iframe框架的页面缓存的方法方法两个:
1、使用上面的meta头信息,当然如果使用php动态页面,你最好也发送header头信息,禁止下缓存
2、添加一个随机数。在html的后面。呵呵

下面。我们来看下,IE中解决iFrame缓存问题的方法有两种:
(1) 每次主页面刷新时随机更换iframe的name;
(2) 每次主页面刷新时在iframe的src路径页面赋予一个随机get参数,例如:

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

但是呢,我觉得他这种方法过于麻烦,需要区分IE和谷歌然后分别来写相应的实现方式。
下面来说一种不需要区分就能没有缓存的方法:

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

转载请注明:(●--●) Hello.My Weicot » 兼容解决 火狐、谷歌 包括IE 、浏览器中 Iframe框架的页面缓存的方法

蜀ICP备15020253号-1