2010年11月11日 星期四

iframe依內容自動調整框架高度

iframe在網頁應用相當的廣泛,但由於先天的限制下
以至於高度以及寬度都只能依所設定的大小為主
但經由後天的調整下,讓iframe也能依載入網頁內容的多寡
自動調整框架大小,iframe也是可以很smart的喔!
製作方法:
1. iframe.htm

<iframe frameborder="0" src="source.htm" id="frameid"></iframe>


2.source.htm(加在<head>….</head>之間 
<script language="javascript">
function reSize(){
  parent.document.all.frameid.height=document.body.scrollHeight; 
} 
window.onload=reSize;
</script>

沒有留言:

張貼留言