Iframeフレーム高さ適応

3550 ワード


( )	Iframe          
Iframe          ,         ,        A.html iframe  B.htm(        )       .        ,        ie6,ie7,ff,opera,      ie6,ie7,ff,opera          ,       ,                <script type=”text/javascript” src=”iframeAutoFit.js” mce_src=”iframeAutoFit.js”></script> 
function iframeAutoFit() 
1.	{ 
2.	try 
3.	{ 
4.	if(window!=parent) 
5.	{ 
6.	var a = parent.document.getElementsByTagName("IFRAME"); 
7.	//           (iframe)      ,     。 
8.	for(var i=0; i&lt;a.length; i++) 
9.	{ 
10.	if(a[i].contentWindow==window)//contentWindow       frame  iframe   window   
11.	{ 
12.	
13.	var h1=0, h2=0, d=document, dd=d.documentElement; 
14.	a[i].parentNode.style.height = a[i].offsetHeight +"px"; 
15.	//parentNode   :          . 
16.	//offserHeaight   :       
17.	a[i].style.height = "10px"; 
18.	
19.	if(dd &amp;&amp; dd.scrollHeight) h1=dd.scrollHeight;//scrollHeight  :        
20.	if(d.body) h2=d.body.scrollHeight; 
21.	var h=Math.max(h1, h2);//      
22.	
23.	if(document.all){h += 0;} 
24.	if(window.opera){h += 1;}//   opera    
25.	a[i].style.height = a[i].parentNode.style.height = h +"px"; 
26.	} 
27.	} 
28.	} 
29.	} 
30.	catch (ex){} 
31.	} 
32.	if(window.attachEvent) 
33.	{ 
34.	window.attachEvent("onload", iframeAutoFit); 
35.	//        LoadImg   
36.	} 
37.	else if(window.addEventListener)//  ff 
38.	{ 
39.	window.addEventListener('load', iframeAutoFit, false); 
40.	} 

    iframe(    )        
                iframe       ,                     iframe           ,               ,      ,      ,         ,          。
     :
       :
<script type="text/javascript">
//** iframe       **//
//                  iframe      
//      iframe ID  .   : ["myframe1", "myframe2"],        ,     。
//  iframe ID
var iframeids=["test"]
//           iframe   iframe   yes     ,no     
var iframehide="yes"
function dyniframesize() 
{
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++)
{
if (document.getElementById)
{
//    iframe  
dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
if (dyniframe[i] && !window.opera)
{
dyniframe[i].style.display="block"
if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //         NetScape
dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight; 
else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //         IE
dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
}
}
//             iframe         
if ((document.all || document.getElementById) && iframehide=="no")
{
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}
if (window.addEventListener)
window.addEventListener("load", dyniframesize, false)
else if (window.attachEvent)
window.attachEvent("onload", dyniframesize)
else
window.onload=dyniframesize
</script>