sil*_*ASH 5 javascript php firefox caching
我正在尝试创建一个页面,刷新后会从URL列表中随机加载一个URL.到目前为止,我发现这样做的最好方法是让PHP从文件中随机获取该行,然后将其加载到iframe中.这也允许我在顶部栏上有一个关闭按钮,允许任何加载到iframe中的页面突破.
我遇到的问题是,在几次重新加载后,在firefox中,iframe刚开始恢复到缓存并且不会加载任何新内容.我猜这是一个缓存问题,因为按Ctrl + F5会使iframe加载一个新页面.
我试过放了一堆防缓存meta标签中,以及JavaScript的一个peice的,我就发现这个文章.
到目前为止没有任何工作.有没有人知道一个好的解决方法或在我的代码中看到错误(我非常新手).
谢谢你的帮助!
这是代码:
</html>
<head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="expires" content="FRI, 13 APR 1999 01:00:00 GMT">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function Ionload()
{
$(parent.document).find("iframe").each(function() {
// apply the logic only to the current iframe only
if(this.contentDocument == window.document) {
// if the href of the iframe is not same as
// the value of src attribute then reload it
if(this.src != location.href) {
this.src = this.src;
}
}
});
}
</script>
<?php
class MyClass
{
function GetLine()
{
global $line;
srand ((double)microtime()*1000000);
$f_contents = file ("urlz");
$line = $f_contents[array_rand ($f_contents)];
}
function PrintVar()
{
global $line;
print $line;
}
}
MyClass::GetLine();
?>
<style type="text/css" media="all">
html, body {
height: 100%
}
body {
margin: 0;
overflow: hidden;
}
#topbar {
height: 50px;
width: 100%;
border-bottom: 3px solid #666
}
#page {
height: 100%;
width: 100%;
border-width: 0
}
</style>
</head>
<body>
<div id="topbar">
<a href=<?php MyClass::PrintVar();?> target="_top">close</a>
</div>
</body>
<iframe id="page" name="page" onload="Ionload()" src=<?php MyClass::PrintVar();?> frameborder="0" noresize="noresize"></iframe>
</html>
Run Code Online (Sandbox Code Playgroud)
更新:
在GGG的帮助下,我得到了修复.这是对功能的更改:
function GetLine()
{
global $newline;
srand ((double)microtime()*1000000);
$f_contents = file ("urlz");
$line = $f_contents[array_rand ($f_contents)];
$newline = $line . "?foo=" . rand();
}
Run Code Online (Sandbox Code Playgroud)
我使用随机数而不是序列,因为我不知道如何将序列从一个重载加载到另一个但是这样可行.
我还注意到,如果在页面加载后不到两秒钟内刷新firefox,问题仍然存在,但我可以忍受.
尝试将虚拟查询字符串附加到 URL 上,以便浏览器被迫跳过缓存。
例如,不是 load www.google.com
,而是 load ,www.google.com?foo=N
其中N
是每次加载时递增的数字。
归档时间: |
|
查看次数: |
994 次 |
最近记录: |