如果我理解正确,这里真正的问题是“如何从其父文档访问 IFRAME 内的 DIV?”
我没有用过 EXT JS,所以我不知道它的语法。但这里是基本的 JavaScript。
一、IFRAME中的文件:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Child Document</title>
</head>
<body>
<h1>Child Document</h1>
<div id="stuff">
This is a div with some text in it.
</div>
</body>
</html>
然后是父文档:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Parent Document</title>
<style type="text/css">
#iframe {
width: 250px;
height: 250px;
border: 1px solid #CCC;
}
</style>
</head>
<body>
<h1>Parent Docment</h1>
<form action="" method="get">
<p>
<input type="button" id="get-it" value="Get It" />
</p>
</form>
<iframe src="iframe.html" id="iframe"> </iframe>
<script type="text/javascript">
<!--
function getIt(){
var iframe = document.getElementById("iframe");
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var stuff = innerDoc.getElementById("stuff");
alert(stuff.innerHTML);
}
function init(){
document.getElementById("get-it").onclick = getIt;
}
window.onload = init;
// -->
</script>
</body>
</html>
关键是这样的:
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
这使您可以访问 IFRAME 的文档对象,之后您可以正常使用它。