window.frames[iframe].document 在ie可以用,在360、火狐中都不兼容?

1 <iframe id="myf" scrolling="auto"    
2           frameborder="0" src="" style="100%;height:100%;">
3 </iframe>

 W3C的标准告诉我们,可以通过Dom对象的contentDocument属性来返回文档对象。IE8开始支持,如果你的项目不用兼容IE6,IE7的话使用这种方式最好。

1 document.getElementById('myf').contentWindow.document //在ie与谷歌都行

    IE6,IE7需要如此访问

1 document.frames('myf').document//ie中可以

   兼容方式: 

1 var doc = document.getElementById('myf' ).contentDocument || document.frames['myf'].document;

  使用Jquery则简单些:

1 $("myf").contents().find("selector");
2 $(window.frames["myf"].document).find("#selector")
1 var doc = window.frames["myf"]. contentDocument || window.frames["myf"]. contentWindow.document;

 获取iframe页面的方法(engineList.jsp)

var creatorInfo=document.getElementById("myf").contentWindow.getCheckedAliyunid();

  注:

 问题:

  document.frames只有IE、Opera浏览器支持,等同于window.frames,用来获取window对象的集合。而在Firefox、Chrome、Safari浏览器中使用document.frames不能获取到Frame元素。

  解决:用window.frames[]代替document.frames()或document.frames[] (window.frames只可写成window.frames['myf']不能写window.frames('myf')

原文地址:https://www.cnblogs.com/hym-pcitc/p/5684054.html