Firefox 的诡异的 iframe 缓存问题

作者: nick 分类: html, web 发布时间: 2010-05-23 14:01 ė 6没有评论

firefox 会缓存 iframe 的内容。但是诡异的是对用动态页面输出的 js 生成的包含静态内容的 iframe 却可能会缓存不该缓存的东西。

test.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> test </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script src="test.php"></script>
</body>
</html>

test.php

<?php
session_start();
if (!isset($_SESSION['test'])) {
$_SESSION['test']=true;
}

if ($_SESSION['test']) {
echo 'document.write(\'<iframe src="test2.htm" name="test"></iframe>\');';
} else {
echo 'document.write(\'<iframe name="test"></iframe>\');';
}
$_SESSION['test'] = !$_SESSION['test'];

test2.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
alert('a~~~~');
parent.location.href=parent.location.href;
</script>
</body>
</html>

比如上面那个例子,访问过一次 test.html 后,再刷新一下,比较一下 firefox 和其他浏览器的差异。

解决办法是,在 js 输出 iframe 后,加一个 iframe.src = iframe.src; ,或者其他的可以刷新内容的东西。

本文出自 传播、沟通、分享,转载时请注明出处及相应链接。

本文永久链接: https://www.nickdd.cn/?p=567

发表评论

您的电子邮箱地址不会被公开。

Ɣ回顶部