我不能清楚地瞭解你的問題。所以我提供了一個通用的解決方案來訪問另一個文件中的iframe內容。希望這對你有幫助。
main.html中
<html>
<head><title>Parent Page</title></head>
<body>
<h3>Parent Page</h3>
<iframe src="a.html" id="one" name="one"></iframe>
<iframe src="b.html" id="two" name="two"></iframe>
</body>
</html>
child1.html
<html>
<head>
<title>Child 1</title>
<script type="text/javascript">
var var1 = 'Test';
function fun1(txt) {
document.getElementById('div1').innerHTML = txt;
}
</script>
</head>
<body>
IFRAME 1 Content in BODY
<div id="div1">Div content of the iframe 1</div>
</body>
</html>
child2.html其中包含兩個文件來源a.html
<html>
<head></head>
<title>Child 2</title>
<body>IFRAME 2<br>
<script type="text/javascript">
function function_in_child2(txt) {
var res1 = parent.one.document.body.innerHTML; //this gets the content of the IFRAME1 named as "one" in main.html
alert(res1);
var getvar1 = parent.one.var1; // gets the value of the variable "var1", which is defined in the child1 (iframe1 named as "one" in parent form)
document.getElementById('div2').innerHTML = getvar1; //displays the variable var1 in div2
parent.one.fun1("This value goes to fun1 of child1"); // Calls the function "fun1", defined in child1
}
</script>
<div id="div2"></div>
<button onclick="function_in_child2('<b>The text changed from iframe 2</b>')">Click Me</button>
</body>
</html>
有第一個文件main.html中和b.html
您可以使用b.html下面的線
var res1 = parent.one.document.body.innerHTML;
你可以得到變量VAR1的值,它是在a.html通過下面的線
var getvar1 = parent.one.var1;
得到a.html的內容您可以使用以下行調用在a.html中定義的函數fun1
parent.one.fun1("This value goes to fun1 of child1");