如何使用JavaScript刷新页面?
当前回答
如果您正在使用jQuery并希望刷新,请尝试在javascript函数中添加jQuery:
我想在单击oh an h3时从页面中隐藏iframe,对我来说这是有效的,但我无法单击允许我查看iframe的项目,除非我手动刷新浏览器。。。不理想。
我尝试了以下方法:
var hide = () => {
$("#frame").hide();//jQuery
location.reload(true);//javascript
};
将简单的Jane javascript与jQuery混合使用应该会奏效。
// code where hide (where location.reload was used)function was integrated, below
iFrameInsert = () => {
var file = `Fe1FVoW0Nt4`;
$("#frame").html(`<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/${file}\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe><h3>Close Player</h3>`);
$("h3").enter code hereclick(hide);
}
// View Player
$("#id-to-be-clicked").click(iFrameInsert);
其他回答
这适用于所有浏览器:
location.reload();
您可能需要使用
location.reload()
或可能需要使用
location.reload(forceGet)
forceGet是一个布尔值,也是可选的。
如果您希望强制浏览器从服务器获取页面,以便同时清除缓存,请将此参数设置为true
我找到了
window.location.href = "";
or
window.location.href = null;
还进行页面刷新。
这使得移除任何哈希值后重新加载页面变得非常容易。当我在iOS模拟器中使用AngularJS时,这非常好,因此我不必重新运行应用程序。
$(document).on("click", "#refresh_btn", function(event)
{
window.location.replace(window.location.href);
});
你可以用两种方式写。第一种是重新加载页面的标准方式,也称为简单刷新
location.reload(); //simple refresh
另一种叫做硬刷新。在这里传递布尔表达式并将其设置为true。这将重新加载页面,销毁旧缓存并从头开始显示内容。
location.reload(true);//hard refresh