如何使用JavaScript刷新页面?
当前回答
有很多方法可以重新加载当前页面,但使用这些方法,您可以看到页面更新,但不会有很少的缓存值,因此要克服这个问题,或者如果您希望发出硬请求,请使用以下代码。
location.reload(true);
//Here, it will make a hard request or reload the current page and clear the cache as well.
location.reload(false); OR location.reload();
//It can be reload the page with cache
其他回答
use
location.reload();
or
window.location.reload();
您应该使用以下代码
window.location.reload();
如果您正在使用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);
我找到了
window.location.href = "";
or
window.location.href = null;
还进行页面刷新。
这使得移除任何哈希值后重新加载页面变得非常容易。当我在iOS模拟器中使用AngularJS时,这非常好,因此我不必重新运行应用程序。
你们可能需要使用
location.reload(forceGet)
forceGet是一个布尔值,也是可选的。
默认值为false,这将重新加载缓存的页面。
推荐文章
- 我如何使用Jest模拟JavaScript的“窗口”对象?
- 我如何等待一个承诺完成之前返回一个函数的变量?
- 在JavaScript中根据键值查找和删除数组中的对象
- 使嵌套JavaScript对象平放/不平放的最快方法
- 如何以及为什么'a'['toUpperCase']()在JavaScript工作?
- 有Grunt生成index.html不同的设置
- 文档之间的区别。addEventListener和window。addEventListener?
- 如何检查动态附加的事件监听器是否存在?
- 防止在ASP中缓存。NET MVC中使用属性的特定操作
- 如何写setTimeout与参数Coffeescript
- 将JavaScript字符串中的多个空格替换为单个空格
- jQuery: keyPress退格键不火?
- XMLHttpRequest Origin null不允许Access-Control-Allow-Origin for file:/// to file:///(无服务器)
- JavaScript: override alert()
- 重置setTimeout