62,074
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>主页</title>
<script type="text/javascript">
//拖动窗体触发事件
var resizeTimer = null;
window.onresize = function()
{
if(resizeTimer==null)
{
resizeTimer = setTimeout("doResize()",300); //控制调用方法的时间间隔
}
}
function doResize()
{
findDimensions('iframe',true);
resizeTimer=null;
}
//实时获取浏览器宽度和高度;
var winWidth = 0;
function findDimensions(iframeName,resize) //函数:获取尺寸
{
//获取窗口宽度
if (window.innerWidth) { winWidth = window.innerWidth; }
else if ((document.body) && (document.body.clientWidth)) { winWidth = document.body.clientWidth; }
//通过深入Document内部对body进行检测,获取窗口大小
if (document.documentElement && document.documentElement.clientWidth) { winWidth = document.documentElement.clientWidth; }
//拖动浏览器的时候,调用的调整iframe方法,参数(iframe ID ,浏览器宽度)
alert('onresize方法被调用 ');//
dyniframesize(iframeName,winWidth);
}
//此段代码用于动态设置ifream宽度
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraWeight=getFFVersion>=0.1? 16 : 0
function dyniframesize(iframeName,winWidth)
{
var pTar = null;
if (document.getElementById) { pTar = document.getElementById(iframeName); }
else { eval('pTar = ' + iframeName + ';'); }
if (pTar && !window.opera)
{
pTar.style.display="block";
if (pTar.Document && pTar.Document.body.offsetWidth)
{
//这段代码动态设置winWidth
if(winWidth < pTar.Document.body.scrollWidth)
{
pTar.width = pTar.Document.body.scrollWidth + 50 ;
}
else
{
pTar.width='100%';
}
alert(pTar.Document.body.scrollWidth); //★如果注销此行,在ie6中将无限调用onresize方法。
}
}
}
</script>
</head>
<body>
<!-- ★如果去掉DIV标记,onresize方法也会执行,宽度重复+ 50px,但是只提示信息只显示1次或者2次。 注:内容需要DIV不能去掉 -->
<div>
<iframe id="iframe" frameborder="1" scrolling="no" width="100%" height="100%" src="sub.html" onload="findDimensions('iframe')" ></iframe>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>sub</title>
</head>
<body style="text-align: center">
<table border="3" width="800px" style="text-align: center">
<tr>
<td>
1</td>
<td>
2</td>
<td style="text-align: left">
3</td>
</tr>
</table>
</body>
</html>