62,074
社区成员
发帖
与我相关
我的任务
分享
function SetImgSrc() {
var ifr2 = document.getElementById("MainIframe").contentWindow.document.getElementById("Iframe2");
if (ifr2) {
var img = ifr2.contentWindow.document.getElementById("img的id");
if (img) {
img.src = "图片路径";
}
}
}
iframe父子窗口间js方法调用2009-04-15 15:38父窗口调用iframe子窗口方法
<iframe name="myFrame" src="child.html"></iframe>
myFrame.window.functionName();
iframe子窗口调用父窗口方法
parent.functionName();
父窗口页面
<html>
<head>
<script type="text/javascript">
function say() {
alert("parent.html------>I'm at parent.html");
}
function callChild()
{
//document.frames("myFrame").f1();
myFrame.window.say();
}
</script>
</head>
<body>
<input type=button value="调用child.html中的函数say()" onclick="callChild()">
<iframe name="myFrame" src="child.html"></iframe>
</body>
</html>
子窗口页面
<html>
<head>
<script type="text/javascript">
function say()
{
alert("child.html--->I'm at child.html");
}
function callParent() {
parent.say();
}
</script>
</head>
<body>
<input type=button value="调用parent.html中的say()函数" onclick="callParent()">
</body>
</html>