<html>
<script type="text/javascript">
function func() {
alert(document.getElementById('iView').contentDocument);
}
</script>
<body>
<iframe id="iView" style="width:200px;height:200px;"></iframe>
<a href="#" onclick="func();">click</a>
</body>
</html>
单击后,Firefox返回object HTMLDocument。Internet Explorer返回undefined。
如何使用Internet Explorer选择iView元素?谢谢。
发布于 2009-09-25 14:20:48
您似乎想要获取iframe的内容,对吗?
IE7和FF2:
var iframe = document.getElementById('iView');
alert(iframe.contentWindow.document.body.innerHTML);
发布于 2009-09-25 14:54:30
使用功能检测,因为IE 8支持contentDocument
:
var iframe = document.getElementById("iView");
var iframeDocument = null;
if (iframe.contentDocument) {
iframeDocument = iframe.contentDocument;
} else if (iframe.contentWindow) {
// for IE 5.5, 6 and 7:
iframeDocument = iframe.contentWindow.document;
}
if (!!iframeDocument) {
// do things with the iframe's document object
} else {
// this browser doesn't seem to support the iframe document object
}
发布于 2012-04-04 13:06:40
contentWindow.document.body.innerHTML
在Internet Explorer和Firefox中为我工作,而
contentDocument.body.innerHTML
只能在Firefox中工作。
https://stackoverflow.com/questions/1477547
复制相似问题