如何使用JavaScript刷新页面?


当前回答

我想有很多方法会奏效:

window.location.reload();history.go(0);window.location.href=window.location.html;

其他回答

<i id="refresh" class="fa fa-refresh" aria-hidden="true"></i>

<script>
$(document).on('click','#refresh',function(){
   location.reload(true);
});
</script>

使用JavaScript刷新页面有多种无限方式:

location.reload()历史记录.go(0)location.href=位置.hreflocation.href=位置.pathnamelocation.replace(location.pathname)location.reload(false)如果我们需要从再次打开web服务器(例如文档内容动态更改),我们会将参数传递为true。

您可以继续列表中的创意:

window.location=窗口位置window.self.window.self.window.window.location=窗口位置…和其他534种方式

var方法=[“location.reload()”,“history.go(0)”,“location.href=位置.href”,“location.href=位置.路径名”,“location.replace(location.pathname)”,“location.reload(false)”];var$body=$(“body”);for(var i=0;i<methods.length;++i){(函数(cMethod){$body.append($(“<button>”{text:c方法}).on(“单击”,函数(){eval(cMethod);//不要怪我使用eval}));})(方法[i]);}按钮{背景:#2ecc71;边框:0;颜色:白色;字号:粗体;字体系列:“Monaco”,monospace;填充:10px;边界半径:4px;光标:指针;过渡:背景色0.5s轻松;边距:2px;}按钮:悬停{背景:#27ae60;}<script src=“https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js“></script>

问题应该是,

如何使用JavaScript刷新页面

window.location.href = window.location.href; //This is a possibility
window.location.reload(); //Another possiblity
history.go(0); //And another

你被宠坏了。

这适用于所有浏览器:

location.reload();

这对我有用。

function reload(){
    location.reload(true);
}