如何使用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);
其他回答
jQueryLoad函数还可以执行页面刷新:
$('body').load('views/file.html', function () {
$(this).fadeIn(5000);
});
我找到了
window.location.href = "";
or
window.location.href = null;
还进行页面刷新。
这使得移除任何哈希值后重新加载页面变得非常容易。当我在iOS模拟器中使用AngularJS时,这非常好,因此我不必重新运行应用程序。
如果当前页面是通过POST请求加载的,您可能需要使用
window.location = window.location.pathname;
而不是
window.location.reload();
因为如果在POST请求加载的页面上调用window.location.reload()将提示确认。
您可以使用JavaScript location.reload()方法。此方法接受布尔参数。正确或错误。如果参数为真;页面总是从服务器重新加载。如果是假的;这是默认设置,或者使用空参数浏览器从其缓存中重新加载页面。
带真参数
<button type="button" onclick="location.reload(true);">Reload page</button>
带默认/假参数
<button type="button" onclick="location.reload();">Reload page</button>
使用jquery
<button id="Reloadpage">Reload page</button>
<script type="text/javascript">
$('#Reloadpage').click(function() {
location.reload();
});
</script>
如果您正在使用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);
推荐文章
- 如何为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方法