开发者

onclick refresh but not from cache?

I have this button to refresh the page

echo '<input type="button" value="Reload 开发者_Python百科Page" 
              onClick="window.location.href = window.location.pathname;">';

What is the easiest way to make sure that the page is read not from cache? To use Math.random() Something like

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


To reload from server use:

window.location.reload(true)

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


Using Math.random() will work, so will (new Date()).getTime() also works.


The most reliable way of doing this is via server side, by setting the header:

Cache-Control: no-cache

See this article for more details.


instead of javascript why not link directly

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

instead?

Edit :: As i note I only suggest this because you included the sample php within your original post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜