Heim  >  Artikel  >  Web-Frontend  >  js中访问html中iframe的文档对象的代码[IE6,IE7,IE8,FF]_javascript技巧

js中访问html中iframe的文档对象的代码[IE6,IE7,IE8,FF]_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:12:32930Durchsuche


W3C的标准告诉我们,可以通过Dom对象的contentDocument属性来返回文档对象。

复制代码 代码如下:

doc= document.getElementById('myframe' ).contentDocument


但对IE浏览器来说,经过测试,IE6,IE7都不支持,IE8开始支持了。
在IE下,需要这样来访问
复制代码 代码如下:

document.frames['myframe'].document;


跨浏览器的解决方案是,
contentWindow属性,这是个只读属性,返回指定的iframe的窗口对象。
它虽然不是标准的一部分,但各个主流浏览器都支持。
所以跨浏览器访问iframe文档对象的方法是
复制代码 代码如下:

document.getElementById( 'myframe').contentWindow.document
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn