当页面中的iframe高度隐藏,如何计算父页面的滚动条被卷去的高度这个问题甚是头疼,是这样的:<html>
...
<head>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("FrmMain");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}
catch (ex){}
}
window.setInterval("reinitIframe()", 500);
</script>
</head>
<body>
<div>
sssssssssss
</div>
<div>
<iframe src="HTMLPage.htm" frameborder="0" id="FrmMain" name="FrmMain" scrolling="no" width="100%" height="0px" allowTransparency="true" onload="reinitIframe()"></iframe>
</div>
</body>
上面用方法reinitIframe()计算了内页的高度,让iframe能自适应,但是现在碰到一个问题:
在iframe内部页面中不能获取外面也没的滚动条被卷去了多少高度?我需要计算滚动条当前滚动的位置,显示div层。有哪位高手能帮忙解决下啊,求救……
...
<head>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("FrmMain");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}
catch (ex){}
}
window.setInterval("reinitIframe()", 500);
</script>
</head>
<body>
<div>
sssssssssss
</div>
<div>
<iframe src="HTMLPage.htm" frameborder="0" id="FrmMain" name="FrmMain" scrolling="no" width="100%" height="0px" allowTransparency="true" onload="reinitIframe()"></iframe>
</div>
</body>
上面用方法reinitIframe()计算了内页的高度,让iframe能自适应,但是现在碰到一个问题:
在iframe内部页面中不能获取外面也没的滚动条被卷去了多少高度?我需要计算滚动条当前滚动的位置,显示div层。有哪位高手能帮忙解决下啊,求救……
将下列代码放到主框架页面就可以解决该问题。function reinitIframe()
{
var iframe = document.getElementById("FrmMain");
try
{
if (!/*@cc_on!@*/0)
{//不是IE浏览器
iframe.onload = function()
{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight); iframe.height = height;
};
}
else
{
if (iframe.readyState == "complete")
{
if (iframe.Document && iframe.Document.body.scrollHeight)
{
iframe.height = iframe.Document.body.scrollHeight;
}
else if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight)
{
alert(iframe.contentDocument.body.offsetHeight);
iframe.height = iframe.contentDocument.body.offsetHeight;
}
}
}
}
catch (ex) { }
}
window.setInterval("reinitIframe()", 200);
另外,2#说话注意点,希望你素质提高点。如果你不会,大家都能理解,但得谦虚点问人家。
我们都是年轻人,我们都对编程感兴趣.
我都有上进心,我们要进步,我们要充实自己.
因为我们年轻,所以我们都有资本.