left.html<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Left</title>
</head><body style="background:#00CCFF">
leftFrame
<script language="javascript">
// alert(1); // 添加alert后,可以显示document.write("a=" + a + " b=" + b);
// var tipBody = parent.mainFrame.document.body;
var tipBody = parent.leftFrame.document.body; // leftFrame可以显示,mainFrame不可以
var a = tipBody.clientWidth;
var b = tipBody.clientHeight;
document.write("a=" + a + " b=" + b);
</script>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Left</title>
</head><body style="background:#00CCFF">
leftFrame
<script language="javascript">
// alert(1); // 添加alert后,可以显示document.write("a=" + a + " b=" + b);
// var tipBody = parent.mainFrame.document.body;
var tipBody = parent.leftFrame.document.body; // leftFrame可以显示,mainFrame不可以
var a = tipBody.clientWidth;
var b = tipBody.clientHeight;
document.write("a=" + a + " b=" + b);
</script>
</body>
</html>
解决方案 »
- 评论框的内容怎么用js隐藏和显现?
- JavaScript连接数据库,能连接,执行没结果
- js如何传递这样的值
- 如何实现这种效果
- 如何用javascript在sharepoint取数据,并在photoshop中用scriptUI去显示?
- 这个问题也许很简单,也许很难,关于在网页上写字的.
- 主窗口弹出一个“非本地链接”的窗口,弹出窗口中有一个变量A,主窗口中有一个变量B,怎样才能在主窗口中对这个“非本地链接”的弹出窗口
- 为什么网页无法调用我做的ocx控件里的函数呢?急啊?help Me!
- radiobutton中触发onchange的时候,如何得到原来被checked的item的值?
- help:如何在javascript取得test.htm?id=ddd后面id的值?
- 一个分页js代码导致网页windows media player停止播放
- 升星了,散分了。
好像网页加载速度太快,在left.html中,javascript调用到main.html中的body的长度等信息(mainFrame框架没有被获取)??? 先看代码:很简单的, 后面有提问. index.html HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Index</title>
</head>
<frameset rows="80,*" cols="*" frameborder="no" border="1" framespacing="0">
<frame src="top.html" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
<frameset cols="180,*" frameborder="no" border="1" framespacing="0">
<frame src="left.html" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" title="leftFrame" />
<frame src="main.html" name="mainFrame" id="mainFrame" title="mainFrame" />
</frameset>
</frameset>
<noframes><body>
</body>
</noframes>
</html>
top.html HTML code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>topFrame</title>
</head>
<body style="background:#3399FF">
topFrame
</body>
</html>
left.html HTML code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>leftFrame</title>
</head>
<body style="background:#00CCFF">
leftFrame
<script language="javascript">
function sayMainParm(){
var tipBody = parent.mainFrame.document.body;
var a = tipBody.clientWidth;
var b = tipBody.clientHeight;
document.write("a=" + a + " b=" + b); //不能显示
}
</script>
</body>
</html>
main.html HTML code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>mainFrame</title>
<script>
function sayParm(){
parent.leftFrame.sayMainParm();
}
</script>
</head>
<body style="background:#CCCCCC" onload = sayParm()>
mainFrame
</body>
</html>
没测试,请自行测试一下.
function chkFrame(){
if(parent.rightFrame.document.body){
tipBody = parent.rightFrame.document.body;
doMyWork(); //有mainFrame后处理的事情
}
else{
setTimeout("chkFrame()",1000);
}
}
chkFrame();
</script>
以上代码,会出错率为50%