如何使用JavaScript刷新页面?
当前回答
您可能想使用
location.reload(forceGet)
forceGet是一个布尔值,也是可选的。
默认值为false,从缓存中重新加载页面。
如果您希望强制浏览器从服务器获取页面,以清除缓存,请将此参数设置为true。
或者只是
location.reload()
如果您想快速方便地使用缓存。
其他回答
我想有很多方法会奏效:
window.location.reload();history.go(0);window.location.href=window.location.html;
这适用于所有浏览器:
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);
问题应该是,
如何使用JavaScript刷新页面
window.location.href = window.location.href; //This is a possibility
window.location.reload(); //Another possiblity
history.go(0); //And another
你被宠坏了。
有很多方法可以重新加载当前页面,但使用这些方法,您可以看到页面更新,但不会有很少的缓存值,因此要克服这个问题,或者如果您希望发出硬请求,请使用以下代码。
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
推荐文章
- 如何为Firebase构建云函数,以便从多个文件部署多个函数?
- 如何发送推送通知到web浏览器?
- AngularJS:工厂和服务?
- js:将一个组件包装成另一个组件
- 父ng-repeat从子ng-repeat的访问索引
- JSHint和jQuery: '$'没有定义
- 模仿JavaScript中的集合?
- 用JavaScript验证电话号码
- 如何在HTML5中改变视频的播放速度?
- 谷歌地图API v3:我可以setZoom后fitBounds?
- 用jQuery检查Internet连接是否存在?
- 如何使用滑动(或显示)函数在一个表行?
- ES6/2015中的null安全属性访问(和条件赋值)
- 与push()相反;
- JS字符串“+”vs concat方法