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


1 <iframe id="myf" scrolling="auto"    
2           frameborder="0" src="" style="width: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')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM