[英]Trigger function from within iframe to parent
我在iframe
具有以下功能:
function modalHgt() {
windowHeight = $(window.parent).height();
complementHeight = $('#complement').outerHeight(true)+20;
popupHeight = $('#main').outerHeight(true);
if ((popupHeight) > (windowHeight-complementHeight)){
popupHeight = windowHeight-complementHeight;
} else {
popupHeight = $('#main').outerHeight(true)+15;
}
$("#sbox-window", top.document).height(popupHeight);
}
调整大小时,我需要在父级中调用相同的函数。 我尝试了以下操作,但不起作用:
$(function() {
var modalHeightTimer;
$(window).resize(function() {
clearTimeout(modalHeightTimer);
modalHeightTimer = setTimeout($.modalHgt, 50);
});
});
您能否建议我如何在父级中调用iframe函数?
modalHeightTimer = setTimeout(window.parent.modalHgt, 50);
让父项在iframe中调用函数:
$('#theIFrame')[0].contentWindow.functionName();
但看起来您的iframe函数是一个匿名的就绪函数,因此,如果您希望父级调用它,则实际上必须在iframe中声明一个函数,例如
function functionName() { //contents; }
如果您想从父母那里叫它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.