用javascript怎样从FRAME外部访问FRAME中的元素?

阅读:8135回复:3
2005-11-26 16:26
写私信
楼主#
用javascript怎样从FRAME外部访问FRAME中的元素?
如从外部访问FRAME中的URL(用户点击过的),如下面一段HTML:
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">

<script language="javascript">
//<!--
function fn1(){
	alert(window.leftFrame);	//IE和FIREFOX都可访问到,firefox提示是window,ie则是object,
	alert(window.leftFrame.document);	//ie出现拒绝访问错误,FF提示是个HTMLDocument
	alert(window.leftFrame.contentDocument);	//和上一个一样
	//接下来.URL .locatin .hrfe .domain .getElementById()所有正常情况下document能用的属性和方法都不能用,FF都出现错误。
	//alert(window.leftFrame.document.URL); 
}
// -->
</script>

<FRAMESET cols=50%,* bordercolor="#3E77B3" name="myFrame">
<FRAME onload="fn1()" name="leftFrame" src="..." bordercolor="#3E77B3">
<FRAME name="rightFrame" src="..." bordercolor="#3E77B3">
</FRAMESET></HEAD><NOFRAMES></NOFRAMES></HTML>

在fn1()中:
alert(window.leftFrame); IE和FIREFOX都可访问到,firefox提示是window,ie则是object.
alert(window.leftFrame.document); ie出现拒绝访问错误,FF提示是个HTMLDocument
alert(window.leftFrame.contentDocument); //和上一个一样
接下来.URL .locatin .hrfe .domain .getElementById()所有正常情况下document能用的属性和方法都不能用,FF都出现错误。
alert(window.leftFrame.document.URL);
后来想用事件来触发来获取状态栏:
IE下 document.onclick="..." 和 FF下document.addEventListener('click', do_somthing, true ); 都没有反应。
window.leftFrame.document.addEventListener('click', do_somthing, true );在FF下就出现错误了。

求救各位高手,怎样从FRAME外部访问FRAME中的元素?
2005-11-26 16:26
写私信
1楼#
试试这个?
document.frames[""]
2005-11-26 16:26
写私信
2楼#
guoshuang:试试这个?
document.frames[""]
回到原帖

谢谢!试过了,一样的.
2005-11-26 16:26
写私信
3楼#
parent.FRAME名.document.form1.abc.value="ok";