bb.html
<a href="http://www.google.com" target="_blank" id="google">www.google.com</a>aa.html
<html>
<head>
</head>
<body>
<iframe id="MyIFrame" name="MyIFrame" src="bb.html">
<script>
var doc;
if (document.all){//IE
doc = document.frames["MyIFrame"].document;
}else{//Firefox
doc = document.getElementById("MyIFrame").contentDocument;
}
alert(doc.getElementById("google").innerHTML);  为什么这里取到iframe中的元素
</script>
</body>
</html>

解决方案 »

  1.   

    必须要等MyIFrame完成加载后取值
      

  2.   

    <iframe id="MyIFrame" name="MyIFrame" src="bb.html">
    上面这句<iframe>标签没有闭合,而且没有设定宽高等属性
    <iframe id="MyIFrame" name="MyIFrame" src="aa.html" width="500" height="500" scrolling="no"></iframe>
    像上面写属性只是个例子保证iframe能显示出来,具体属性根据你的需要再添加修改吧