如何使用JavaScript重新加载页面?
我需要一个方法,工作在所有浏览器。
如何使用JavaScript重新加载页面?
我需要一个方法,工作在所有浏览器。
当前回答
这对我来说很管用:
function refresh() {
setTimeout(function () {
location.reload()
}, 100);
}
http://jsfiddle.net/umerqureshi/znruyzop/
其他回答
这对我来说很管用:
function refresh() {
setTimeout(function () {
location.reload()
}, 100);
}
http://jsfiddle.net/umerqureshi/znruyzop/
JavaScript 1.2及更新版本
window.location.reload();
// If we needed to force the document to be fetched from the
// web server again (such as where the document contents
// change dynamically but cache control headers are not
// configured properly), Firefox supports a non-standard
// parameter that can be set to true to bypass the cache:
//window.location.reload(true);
JavaScript 1.1
window.location.replace(window.location.pathname + window.location.search + window.location.hash);
// does not create a history entry
JavaScript 1.0
window.location.href = window.location.pathname + window.location.search + window.location.hash;
// creates a history entry
这应该可以工作:
window.location.href = window.location.href.split( '#' )[0];
or
var x = window.location.href;
x = x.split( '#' );
window.location.href = x[0];
我更喜欢这个,原因如下:
删除#后面的部分,确保页面在浏览器上重新加载,而不会重新加载包含该内容的内容。 如果你最近提交了一个表单,它不会询问你是否想要重新发布上一个内容。 它甚至可以在最新的浏览器上运行。在持续的Firefox和Chrome上测试。
或者,您可以使用最新的官方方法完成此任务
window.location.reload()
location.href = location.href;
Try:
window.location.reload(true);
参数设置为'true'从服务器重新加载一个新的副本。省略它将从缓存中提供页面。
更多信息可以在MSDN和Mozilla文档中找到。