javascript 如何从 iframe 内部捕获 iframe resize 事件(iframe 和页面 - 同一域)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9484191/
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 catch iframe resize event from inside the iframe (iframe and the page - same domain)
提问by Yosef
I try to listen from inside of iframe to changes of iframe width/height with:
我尝试从 iframe 内部监听 iframe 宽度/高度的变化:
$(window).resize(function(){
alert('1 on inside iframe');
});
or:
或者:
$(window.parent).find('iframe').resize(function(){
alert('2 on inside iframe');
});
but nothing happens when iframe size changes. (I need a cross-browser solution: IE7, Chrome, Firefox, Safari.)
但是当 iframe 大小改变时什么也没有发生。(我需要一个跨浏览器的解决方案:IE7、Chrome、Firefox、Safari。)
回答by Rizwan Mumtaz
$(body).resize(function(){
alert('on inside iframe');
});
Edit :
编辑 :
in html
在 html 中
<body onresize="myFunction()">
回答by Nick Beranek
You need to call the resize()
handler from the parent
document on the iframe
:
您需要resize()
从以下parent
文档中调用处理程序iframe
:
$('iframe').resize(function() {} );