IE中的getElementById.contentDocument错误 [英] getElementById.contentDocument error in IE

查看:216
本文介绍了IE中的getElementById.contentDocument错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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。

After click, Firefox returns [object HTMLDocument]. Internet Explorer returns undefined.

如何使用Internet Explorer选择iView元素?谢谢。

How can I select the iView element with Internet Explorer? Thanks.

推荐答案

来自此页面


Mozilla支持通过iframe的文档对象访问的W3C标准IFrameElm.contentDocument,而Internet Explorer要求您通过document.frames [name]访问它,然后访问生成的文档。

Mozilla supports the W3C standard of accessing iframe's document object through IFrameElm.contentDocument, while Internet Explorer requires you to access it through document.frames["name"] and then access the resulting document.

所以你需要检测浏览器并在IE上做这样的事情:

So you need to detect the browser and on IE do something like this instead:

document.frames['iView'].document; 

这篇关于IE中的getElementById.contentDocument错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆