当我按下iframe中的按钮时,它会消失标签,但不会调整iframe的大小。当ajax完成时,应调用另一页中的AjustResizeIframeHeight方法 有什么建议吗?
更新
包含iframe的页面
<script language="javascript" type="text/javascript">
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
function AdjustIframeHeight(i) { document.getElementById("form-iframe").style.height = parseInt(i) + "px"; }
</script>
<iframe id"form-iframe" width="100%" style="border: none" src="{{ notes }}" onload='javascript:resizeIframe(this);'>
</iframe>
内容iframe:
<a href="#" onclick="xpto2(1,{{ n.id }});parentNode.parentNode.removeChild(parentNode)" >Don't show again</a>
<script>
function xpto2(status,noteid) {
var request = $.ajax({
....
});
request.done(function() {
window.parent.AdjustIframeHeight();
});
}
</script>
在ajax函数中添加了window.parent.AdjustIframeHeight()
,但它表示“未解析的函数或方法”
答案 0 :(得分:0)
getElementById("form- iframe")
将找不到任何内容,因为没有标识为form- iframe
的元素。window.parent.AdjustIframeHeight()
访问该功能。Window.postMessage
并在父页面上侦听message
个事件。答案 1 :(得分:0)
<强>解决强> 解决方案是添加一个div,然后将div调用方法
包含iframe的页面
<script language="javascript" type="text/javascript">
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
function AdjustIframeHeight(i) {parent.AdjustIframeHeight(document.getElementById("page").scrollHeight);
</script>
<iframe id"form-iframe" width="100%" style="border: none" src="{{ notes }}" onload='javascript:resizeIframe(this);'>
</iframe>
内容iframe:
<div id="page">
<a href="#" onclick="xpto2(1,{{ n.id }});parentNode.parentNode.removeChild(parentNode)" >Don't show again</a>
<\div>
<script>
function xpto2(status,noteid) {
....
});
request.done(function() {
request.done(function() {
parent.AdjustIframeHeight(document.getElementById("page").scrollHeight);
});
}
</script>