去掉iframe横向滚动条_iframe滚动条

主页面加IFRAME SCROLLING="YES"

子页面
'让竖条消失: 
<BODY STYLE='OVERFLOW:SCROLL;OVERFLOW-Y:HIDDEN'> 
</BODY> 
'让横条消失: 
<BODY STYLE='OVERFLOW:SCROLL;OVERFLOW-X:HIDDEN'> 
</BODY>

'还要去掉
'子页面里的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
'两个都去掉

 


iframe自动适应页面大小JS函数

//Iframe自适应高度/宽度  
function dynIframeAutoSize(iFrameName,autoType) 
{ 
debugger 
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]; 
//extra height in px to add to iframe in FireFox 1.0+ browsers 
//高度 
var FFextraHeight=getFFVersion>=0.1? 16 : 0 ; 
//宽度 
var FFextraWidth=getFFVersion>=0.1? 16 : 0 ; 
var objElement = null; 
if (document.getElementById) 
objElement = document.getElementById(iFrameName); 
else 
eval('pTar = ' + iFrameName + ';'); 
if (objElement && !window.opera) 
{ 
//begin resizing iframe 
objElement.style.display="block"; 
switch(autoType) 
{ 
case "height": 
//高度 
if (objElement.contentDocument && objElement.contentDocument.body.offsetHeight) 
//ns6 syntax 
objElement.height = objElement.contentDocument.body.offsetHeight+FFextraHeight; 
else if (objElement.Document && objElement.Document.body.scrollHeight) 
//ie5+ syntax 
objElement.height = objElement.Document.body.scrollHeight; 
break; 
case "width": 
//宽度 
if (objElement.contentDocument && objElement.contentDocument.body.offsetWidth) 
//ns6 syntax 
objElement.width = objElement.contentDocument.body.offsetWidth+FFextraWidth; 
else if (objElement.Document && objElement.Document.body.scrollWidth) 
//ie5+ syntax 
objElement.width = objElement.Document.body.scrollWidth; 
break; 
default: 
//适应大小(高和宽)  
//高度 
if (objElement.contentDocument && objElement.contentDocument.body.offsetHeight) 
//ns6 syntax 
objElement.height = objElement.contentDocument.body.offsetHeight+FFextraHeight; 
else if (objElement.Document && objElement.Document.body.scrollHeight) 
//ie5+ syntax 
objElement.height = objElement.Document.body.scrollHeight; 
//宽度 
if (objElement.contentDocument && objElement.contentDocument.body.offsetWidth) 
//ns6 syntax 
objElement.width = objElement.contentDocument.body.offsetWidth+FFextraWidth; 
else if (objElement.Document && objElement.Document.body.scrollWidth) 
//ie5+ syntax 
objElement.width = objElement.Document.body.scrollWidth; 
break; 
} 
} 
}

 

 

方法一:在父页面中

<div id="div1"><iframe name=... src=http://www.cnblogs.com/... style="Z-INDEX: 2; VISIBILITY: inherit; WIDTH: 100%; HEIGHT: 100%" frameborder="0" scrolling="no"></iframe></div>

iframe中页面:

function window.onload()
{
var div = window.parent.document.getElementById('div1');
div.style.height=document.body.scrollHeight+20;
}
方法二:

<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>


使用的时候只要贴在<head></head>里面就可以了

posted @ 2011-06-09 10:31  Happy Hu  Views(8275)  Comments(0Edit  收藏  举报