您的位置:首页 > 其它

禁止火狐浏览器缓存input标签

2011-08-02 17:25 387 查看
 如果在网页上用<input taype="hidden" value="xxx">的方式来存储一些变量,值被改变后,按下F5刷新网页,input的值会被Firefox自动还原到刷新前的状态,所以某些时候,一些基于这些值进行的JS事件就无法被初始化,显示悲剧了。

  如果你想让Firefox没有这么智能,不缓存你的input的值的话,需要进行如下修改:

XML/HTML Code复制内容到剪贴板

<form>

<input autocomplete="off" type="text" /><br />

<input autocomplete="off" type="text" /><br />

<input autocomplete="off" type="text" /><br />

<input autocomplete="off" type="text" /><br />

</form>

  以上代码,给每一个input加上一个 autoconplete="off" 的属性,这样,就能阻止Firefox的默认缓存机制了。刷新之后,这些input的值都初始化。

  还有一个写法,可以把全个表单中所有input都设置为不缓存的:

XML/HTML Code复制内容到剪贴板

<form autocomplete="off">

<input type="text" /><br />

<input type="text" /><br />

<input type="text" /><br />

<input type="text" /><br />

</form>

http://www.mayax.net/article/program/331.htm

其他几种禁止浏览器缓存页面的方法:

1.在要禁止缓存的页面<head>中加以下脚本:

Jsp代码



<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

2.在要禁止缓存的页面<head>中加以下脚本:

Jsp代码



<%

response.setHeader("Cache-Control","no-cache");

response.setHeader("Pragma","no-cache");

response.setDateHeader ("Expires", 0);

%>

参考网址:
http://oldboy.iteye.com/blog/466595 ie和火狐缓存的区别
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: