如何使用JavaScript刷新页面?
当前回答
可能最短(12个字符)-使用历史
history.go()
其他回答
jQueryLoad函数还可以执行页面刷新:
$('body').load('views/file.html', function () {
$(this).fadeIn(5000);
});
我找到了
window.location.href = "";
or
window.location.href = null;
还进行页面刷新。
这使得移除任何哈希值后重新加载页面变得非常容易。当我在iOS模拟器中使用AngularJS时,这非常好,因此我不必重新运行应用程序。
下面是一些代码行,您可以使用jQuery重新加载页面。
它使用jQuery包装器并提取本地dom元素。
如果您只想在代码上获得jQuery的感觉,而不关心代码的速度/性能,请使用此选项。
只需从1到10中选择适合您的需求,或者根据模式和之前的答案添加更多内容。
<script>
$(location)[0].reload(); //1
$(location).get(0).reload(); //2
$(window)[0].location.reload(); //3
$(window).get(0).location.reload(); //4
$(window)[0].$(location)[0].reload(); //5
$(window).get(0).$(location)[0].reload(); //6
$(window)[0].$(location).get(0).reload(); //7
$(window).get(0).$(location).get(0).reload(); //8
$(location)[0].href = ''; //9
$(location).get(0).href = ''; //10
//... and many other more just follow the pattern.
</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);
使用JavaScript刷新页面有多种无限方式:
location.reload()历史记录.go(0)location.href=位置.hreflocation.href=位置.pathnamelocation.replace(location.pathname)location.reload(false)如果我们需要从再次打开web服务器(例如文档内容动态更改),我们会将参数传递为true。
您可以继续列表中的创意:
window.location=窗口位置window.self.window.self.window.window.location=窗口位置…和其他534种方式
var方法=[“location.reload()”,“history.go(0)”,“location.href=位置.href”,“location.href=位置.路径名”,“location.replace(location.pathname)”,“location.reload(false)”];var$body=$(“body”);for(var i=0;i<methods.length;++i){(函数(cMethod){$body.append($(“<button>”{text:c方法}).on(“单击”,函数(){eval(cMethod);//不要怪我使用eval}));})(方法[i]);}按钮{背景:#2ecc71;边框:0;颜色:白色;字号:粗体;字体系列:“Monaco”,monospace;填充:10px;边界半径:4px;光标:指针;过渡:背景色0.5s轻松;边距:2px;}按钮:悬停{背景:#27ae60;}<script src=“https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js“></script>
推荐文章
- 我如何使用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