如何使用JavaScript刷新页面?


当前回答

$(document).on("click", "#refresh_btn", function(event) 
{
     window.location.replace(window.location.href);
});

其他回答

如果当前页面是通过POST请求加载的,您可能需要使用

window.location = window.location.pathname;

而不是

window.location.reload();

因为如果在POST请求加载的页面上调用window.location.reload()将提示确认。

jQueryLoad函数还可以执行页面刷新:

$('body').load('views/file.html', function () {
    $(this).fadeIn(5000);
});

简单的Javascript解决方案:

 location = location; 

<buttonClick=“location=location;”>重新加载</button>

window.location.reload()将从服务器重新加载,并将再次加载所有数据、脚本、图像等。

因此,如果您只想刷新HTML,window.location=document.URL将返回得更快,流量更少。但如果URL中有散列(#),则不会重新加载页面。

在按钮标记中使用onclick=“return location.reload();”。

<button id="refersh-page" name="refersh-page" type="button" onclick="return location.reload();">Refesh Page</button>