如何使用JavaScript刷新页面?
当前回答
这适用于所有浏览器:
location.reload();
其他回答
jQueryLoad函数还可以执行页面刷新:
$('body').load('views/file.html', function () {
$(this).fadeIn(5000);
});
您不需要jQuery中的任何东西,要使用纯JavaScript重新加载页面,只需在location属性上使用reload函数,如下所示:
window.location.reload();
默认情况下,这将使用浏览器缓存(如果存在)重新加载页面。。。
如果您想强制重新加载页面,只需传递一个true值来重新加载方法,如下所示。。。
window.location.reload(true);
此外,如果您已经在窗口范围内,您可以删除窗口并执行以下操作:
location.reload();
这适用于所有浏览器:
location.reload();
这对我有用。
function reload(){
location.reload(true);
}
<i id="refresh" class="fa fa-refresh" aria-hidden="true"></i>
<script>
$(document).on('click','#refresh',function(){
location.reload(true);
});
</script>