请知悉:本文最近一次更新为 8年 前,文中内容可能已经过时。

嵌入的iframe,从子iframe控制父窗体的其他iframe之类的相关记录:
1.初始化iframe大小:

<script type="text/javascript">
function setIframeHeight(id) {
try {
var iframe = document.getElementById(id);
if (iframe.attachEvent) {
iframe.attachEvent("onload",
function() {
iframe.style.height = iframe.contentWindow.document.documentElement.scrollHeight + "px"
});
return
} else {
iframe.onload = function() {
iframe.style.height = iframe.contentDocument.body.scrollHeight + "px"
};
return
}
} catch(e) {
throw new Error('setIframeHeight Error');
}
}
setIframeHeight("faq");
</script>
/*iframe.style.height=(document.documentElement.clientHeight-56)+"px";*/

在iframe之后执行,可以初始化iframe的高度,当然啦,配合onload会更好,自己琢磨。

2.子iframe控制父窗体的其他iframe历史后退以及跳转:

<script type="text/javascript">
function $(id){
return window.parent.document.getElementById(id);
}
function golink(url){
$('faq').src=url;
}
</script>

示例代码:

golink('abc.html');
$('faq').contentWindow.history.back(-1);

3.父调用子窗口的元素

document.iframes('iframe').contentWindow.document

如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《iframe-JavaScript操作相关记录》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌