亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

深入解析contentWindow, contentDocument

 更新時間:2013年07月04日 14:47:59   投稿:jingxian  
沒有永恒的技術(shù)只有需求,沒有好說的客戶只有無奈的開發(fā)者,如果iframe的出現(xiàn)是一個錯誤的話,iframe里邊在來一個iframe那是錯上加錯,神話沒有在遠古的塵囂中消失,卻在懷具的今天不斷上演

生活永遠是一個大染缸,一塊白布下去,黑布出來,一塊黑布下去,一塊七色布出來。

contentWindow 兼容各個瀏覽器,可取得子窗口的 window 對象。
contentDocument Firefox 支持,> ie8 的ie支持??扇〉米哟翱诘?document 對象。

在子級iframe設(shè)置 父級 iframe ,或 孫級 iframe 高度。

function showIframeH(){
  var parentWin = parent.document.getElementById("test");
  if(!parentWin) return false;
  var sub = parentWin.contentWindow.document.getElementById("test2");
  if(!sub) return false;
  var thirdHeight = sub.contentWindow.document.body.offsetHeight; //第三層 body 對象
  sub.height = thirdHeight; //設(shè)置第二層 iframe 的高度
  var secondHeight = x.contentWindow.document.body.offsetHeight; //第二層 body 對象
  x.height = secondHeight; //設(shè)置第一層 iframe 的高度
  //alert(secondHeight);
  //alert('body: ' + x.contentDocument.body.offsetHeight + ' div:' + thirdHeight);
}

下面附一個實例,因為2345的推廣,很多導(dǎo)航站都將網(wǎng)址直接換成2345的推廣頁面了,那就是當(dāng)前域名下獲取2345中的寬度,然后通過js設(shè)置iframe內(nèi)容的高度,這樣看起來是一個整體,核心內(nèi)容如下

iframe

<body>
<iframe id="mainFrame" onload="mainFrameLoaded(this)" scrolling="no" src="https://www.2345.com/"></iframe>

js代碼

<script>
	function mainFrameLoaded(t) 
	{
		//debugger;
		//alert(t.contentWindow.document.body.offsetHeight);
  t.style.height = t.contentWindow.document.body.offsetHeight + 'px';
	}
</script>

記住js寫在前面,iframe在后面,通過onload加載的時候就觸發(fā),完美融合。

相關(guān)文章

最新評論