onclick刷新但不是来自缓存?

时间:2011-03-17 00:58:48

标签: javascript

我有这个按钮来刷新页面

echo '<input type="button" value="Reload Page" 
              onClick="window.location.href = window.location.pathname;">';

确保页面不是从缓存中读取的最简单方法是什么?使用Math.random()类似

的内容
echo '<input type="button" value="Reload Page"  
 onClick="window.location.href = window.location.pathname&\'?t=\'&Math.random();">';

4 个答案:

答案 0 :(得分:4)

从服务器使用重新加载:

window.location.reload(true)

信息:http://www.devguru.com/technologies/ecmascript/quickref/reload.html

答案 1 :(得分:1)

使用Math.random()将起作用,因此(new Date())。getTime()也可以。

答案 2 :(得分:1)

最可靠的方法是通过服务器端设置标题:

Cache-Control: no-cache

有关详细信息,请参阅this文章。

答案 3 :(得分:0)

而不是javascript为什么不直接链接

<?php
echo "<a href='" . $_SERVER['PHP_SELF'] . "&=" . time() . "'>Reload Page</a>";
?>

代替?

编辑::我注意到我只建议这个,因为你在原帖中包含了示例php。