javascript 如何在单击时重新加载 iframe?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12686870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I reload an iframe on click?
提问by Krishna Kumar
Possible Duplicate:
Reload an iframe with jQuery
可能的重复:
使用 jQuery 重新加载 iframe
How can I cause an <iframe>
to reload on a click event?
如何<iframe>
在点击事件上重新加载?
I tried this, but it is not working:
我试过这个,但它不起作用:
jQuery("#link").click(function(){
jQuery('#iframeID')[0].reload();
})
回答by fedmich
like this
像这样
document.getElementById('iframeID').contentWindow.location.reload();
or via
或通过
document.getElementById('iframeID').src = document.getElementById('iframeID').src;
回答by MaVRoSCy
$("#reload").click(function() {
jQuery.each($("iframe"), function() {
$(this).attr({
src: $(this).attr("src")
});
});
return false;
});
This above code will reload every iframe in your page, every time the link with id=reload
is clicked
每次id=reload
点击链接时,上面的代码都会重新加载页面中的每个 iframe
Thanks to @Haim Evgi
感谢@Haim Evgi
Or you can do the same also like this
或者你也可以这样做
$('iframe').each(function() {
this.contentWindow.location.reload(true);
});
回答by Anton
var iframe = document.getElementById('ID');
iframe.src = iframe.src;
回答by Mathlight
You can do something like this:
你可以这样做:
$("#iframe").attr('src', ($('#iframe').attr('src'));