如何使用JavaScript刷新页面?
当前回答
您可能需要使用
location.reload()
或可能需要使用
location.reload(forceGet)
forceGet是一个布尔值,也是可选的。
如果您希望强制浏览器从服务器获取页面,以便同时清除缓存,请将此参数设置为true
其他回答
您不需要jQuery中的任何东西,要使用纯JavaScript重新加载页面,只需在location属性上使用reload函数,如下所示:
window.location.reload();
默认情况下,这将使用浏览器缓存(如果存在)重新加载页面。。。
如果您想强制重新加载页面,只需传递一个true值来重新加载方法,如下所示。。。
window.location.reload(true);
此外,如果您已经在窗口范围内,您可以删除窗口并执行以下操作:
location.reload();
您可能想使用
location.reload(forceGet)
forceGet是一个布尔值,也是可选的。
默认值为false,从缓存中重新加载页面。
如果您希望强制浏览器从服务器获取页面,以清除缓存,请将此参数设置为true。
或者只是
location.reload()
如果您想快速方便地使用缓存。
问题应该是,
如何使用JavaScript刷新页面
window.location.href = window.location.href; //This is a possibility
window.location.reload(); //Another possiblity
history.go(0); //And another
你被宠坏了。
如果您正在使用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);
use
location.reload();
or
window.location.reload();