iframe父子頁面操作-比較好用的兩個方法-window.parent/oframe.contentWindow.document

發現比較好用的iframe父子頁面操作方法,記錄一下


1.父頁面 test.html


  <iframe id="iframe1" src="iframe.html"></iframe>


 獲取iframe    var oframe = document.getElementById("main")


獲取子頁面  var child =  oframe.contentWindow.document


獲取子頁面元素      var test = child.getElementById("test")


獲取子頁面高度   var childh = child .body.offsetHeight


獲取子頁面高度


2.子頁面 iframe.html


  <div id="test"></div>


  獲取父頁面   var parent = window.parent.document


注意:需要把代碼放在服務器端,才能兼容google瀏覽器


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章