var block = document.getElementById(blockid);如何列举出所有 block 下的 iframe
var frm = document.frames; for (i=0; i < frm.length; i++) alert(frm[i].xxxx);
目前是这样做的,但是不知道是不是在block里
var block = document.getElementById(blockid); var frm = block.getElementsByTagName(iframe); for (i=0; i < frm.length; i++) alert(frm[i].contentWindow.xxxx);
for (i=0; i < frm.length; i++) alert(frm[i].xxxx);
var frm = block.getElementsByTagName(iframe);
for (i=0; i < frm.length; i++) alert(frm[i].contentWindow.xxxx);
就是要多建立俩个iframe,通过另外一个iframe来访问你的iframe
下面是例子
主页面代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>主页面 </title>
<script language="javascript">
</script>
</head>
<iframe id="baidu" src="http://baidu.com" name="baidu" > </iframe>
<iframe id="google" src="getDocument2.html" name="google" > </iframe>
<iframe id="getD" src="getDocument.html" name="getD"> </iframe>
<body>
</body>
</html>
getDocument2.html:
<html>
<head>
<script>
window.onload = function (){
alert(3);
alert(parent.document.frames.length);
alert(parent.document.frames["getD"].window.document.getElementById('up'));
alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML);
}
function getdocument(){
alert(4);
alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML);
}
</script>
</head>
<body>
<p id='up'>getDocument2 </p>
<p id='element'>getElement2 </p>
<input type="button" onclick="getdocument();" value="获取iframe"/>
</body>
</html>
getDocument.html:
<html>
<head>
</head>
<body>
<p id='up'>getDocument </p>
<p id='element'>getElement </p>
</body>
</html>
自己运行就可以了
一会儿结帖,要是上不了网就明天结。
帮忙看下这个:http://topic.csdn.net/u/20090718/15/b8ff6bd9-1f60-43bb-bf31-366282fd8f3b.html?seed=1816260280&r=58530188#r_58530188