javascript 在javascript中获取框架的高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3658268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting the height of a frame in javascript
提问by Marcus Fr?din
I'm currently working in a system with a bit of a legacy presentation layer -- it uses frames (actual, in a frameset frames).
我目前在一个带有一些遗留表示层的系统中工作——它使用框架(实际上,在框架集框架中)。
To get some event handling up and running I would like to get events when the frame resizes or at least be able to measure the height of the frame somehow. There seems to be no cross browser way to do this. Has anyone tried anything like this?
为了启动并运行一些事件处理,我想在框架调整大小或至少能够以某种方式测量框架的高度时获取事件。似乎没有跨浏览器的方式来做到这一点。有没有人尝试过这样的事情?
回答by Sachin Shanbhag
Try this - Also you might have to try this on all browsers too -
试试这个 - 你也可能需要在所有浏览器上试试这个 -
<!--
Example File From "JavaScript and DHTML Cookbook"
Published by O'Reilly & Associates
Copyright 2003 Danny Goodman
-->
function getFrameSize(frameID) {
var result = {height:0, width:0};
if (document.getElementById) {
var frame = parent.document.getElementById(frameID);
if (frame.scrollWidth) {
result.height = frame.scrollHeight;
result.width = frame.scrollWidth;
}
}
return result;
}

