都可以,top.框架名.函数名(),但页面必须是在同一域下示例
frame.htm
<frameset cols="200,*">
<frame name=a src="a.htm" />
<frame name=b src="b.htm" />
</frameset>a.htm
<body>A
<button onclick="top.b.AlertMethod()">B alert Method</button>
</body>b.htm
<body>
<script>
function AlertMethod()
{
alert("alert at page b");
}
</script>B
</body>
frame.htm
<frameset cols="200,*">
<frame name=a src="a.htm" />
<frame name=b src="b.htm" />
</frameset>a.htm
<body>A
<button onclick="top.b.AlertMethod()">B alert Method</button>
</body>b.htm
<body>
<script>
function AlertMethod()
{
alert("alert at page b");
}
</script>B
</body>
window.frames['subframe_name'].subframe_fun() //不记得是frames['subframe_name']还是frames('subframe_name') 但是frames[i] (i为该frame出现的位置0开始)
window.subframe_name.subframe_fun()子框架调用父框架可以用:
parent.parentframe_fun() //直接上级
top.parentframe_fun() //直接上级或者顶层frame兄弟框架可以:
parent.brotherframe_name.brotherframe_fun()
其他关系可以据此类推。关键一点是根据文档对象模型进行调用。一般浏览器的Javascript引擎都有个文档对象模型,当然如果实现了DOM(这个跟前面说浏览器本身的文档对象模型不完全相同)的可以根据w3c的DOM模型进行调用。
window.parent.frames['subframe_name'].subframe_fun()
不能跨域是什么意思?
就是只能调用相同网站页面里的js
比如sina.com的页面不能调sohu.com页面里的js,就算把他们放在同一个框架页面里