<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>
After click, Firefox returns [object HTMLDocument]. Internet Explorer returns undefined.
How can I select the iView element with Internet Explorer? Thanks.
The cross-browser equivalent to contentDocument
(including Firefox itself, where contentDocument
does work) is contentWindow.document
.
So try:
alert(document.getElementById('iView').contentWindow.document);
contentWindow
gets you a reference to the iframe's window
object, and of course .document
is just the DOM Document object for the iframe.