看了好几篇文章,试了一些方法,都没有结果。 我需要做的是动态调整父级 iframe 标签的高度。 我无法修改放在 iframe src 上的页面,因为它是另一台服务器的 Intranet 上的应用程序。
我知道存在安全问题,但我需要在页面上使用此功能,因为该应用程序应在 Intranet 网页上无缝显示。 我希望看到实现此目的的选项、方法或解决方法。
我也尝试根据 scroball 调整 iframe 的大小,但没有成功。
任何人都可以帮助我。
最佳答案
父级:
http://jsbin.com/ujAqemI/1/edit
function handleMessage(e) {
if (e.data.action == 'resize') {
var targetHeight = e.data.height;
$('#iFrame').animate({
height: targetHeight
});
}
}
window.addEventListener("message", handleMessage, false);
内嵌框架:
http://jsbin.com/azUWIye/1/edit
parent.postMessage({
'action':'resize',
'height': 400
}, '*');
关于javascript - iframe resize跨域无控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117342/