我想重新加载一个<iframe>使用JavaScript。到目前为止,我发现最好的方法是将iframe的src属性设置为自身,但这不是很干净。什么好主意吗?
当前回答
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
其他回答
window.frames['frameNameOrIndex'].location.reload();
这种方法避免了向某些浏览器添加历史记录(不必要的开销)。正文部分:
<div id='IF'>
<iframe src='https://www.wolframalpha.com/input?i=Memphis%20TN%20Temperature'
style="width:5in; height:6in" // or whatever you want in your Iframe
title'Temperature'></iframe>
</div>
然后在某些JAVASCRIPT中,你可能会有这样的函数:
function UPdate() { // Iframe
T1=document.getElementById('IF')
T2=T1.innerHTML
T1.innerHTML=T2
}
document.getElementById('some_frame_id').contentWindow.location.reload();
注意,在Firefox中,window.frames[]不能通过id索引,而是通过名称或索引
出于调试目的,可以打开控制台,将执行上下文更改为他想要刷新的帧,然后执行document.location.reload()
将空字符串附加到iFrame的src属性也会自动重新加载它。
document.getElementById('id').src += '';
推荐文章
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?
- angularjs中的compile函数和link函数有什么区别
- 删除绑定中添加的事件监听器
- 很好的初学者教程socket.io?
- HtmlSpecialChars在JavaScript中等价于什么?
- React: 'Redirect'没有从' React -router-dom'中导出
- 如何在React中使用钩子强制组件重新渲染?
- 我如何使用Jest模拟JavaScript的“窗口”对象?
- 我如何等待一个承诺完成之前返回一个函数的变量?
- 在JavaScript中根据键值查找和删除数组中的对象
- 使嵌套JavaScript对象平放/不平放的最快方法