Firefox 的诡异的 iframe 缓存问题

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>
  test.php
</body>
</html>

test.php

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

if ($_SESSION['test']) {
    echo 'document.write(\'http://test2.htm\');';
} 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; ,或者其他的可以刷新内容的东西。

3 thoughts on “Firefox 的诡异的 iframe 缓存问题

  1. 零点坐标 May 27, 2010 / 5:23 pm

    到是在mac下,firefox会随机在流览的网页上加一个iframe

    我怎么觉得这个像是电信劫持?

  2. Artur May 22, 2010 / 8:51 am

    动态输出iframe,这个到没试过,到是在mac下,firefox会随机在流览的网页上加一个iframe,这导致网页显示俩个滚动框,而我流览的这个网页跟本就没有iframe,这个是其他页面的iframe,难道这也是firefox的诡异的iframe缓存问题???

  3. 大肥羊 March 2, 2014 / 6:27 pm

    我是这两天发现火狐有这个问题。。。
    不知道是不是装了什么软件或者插件才这样的。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s