javascript怎样以绝对地址的方式取得frame 如题,当我并不知道当前是哪一个页面时,不能以什么window.parent.frames...的形式取,因为当前页面是动态的,我根本不知道当前页面与我需要的frame关系是什么,能否以绝对路径的方式取到 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对,也许是frame,也许是iframe 如果是框架网页,你可以:1、JS实现:在TOP页面:<script>var itparadise=false;var toury=false;//这两个变量就可以实现你的需求</script>当子页面加载时:<script>//改变父页面的全局变量top.itparadise=location.hreftop.toury=true;</script>2、隐藏域实现:在某个frame(比如id='aaa')中设置隐藏域:<script>window.onload=function(){ document.getElementById("itparadise").value="1234567" document.getElementById("toury").value="保存你的数据"}</script><input type='hidden' id="itparadise" /><input type='hidden' id="toury" />这样,可在其他的frame页面中取值:var aaa=top.document.getElementById("aaa").document.getElementById("itparadise").valuevar bbb=top.document.getElementById("aaa").document.getElementById("toury").value 3、服务端变量实现:可通过服务端的session()或application()保存一样不经常变化的数据,客户端需要时,只要var aaa='<%=session("xxx")%>' 这样的形式就可以获得 那就到了正题,我一个框架页面,也许有上中下左右frame,还有嵌套iframe,如何在不定的页面里(有可能是left、right,或是嵌套的frame里),直接找到需要找到top的frame,有无一种绝对路径定位的形式 top.xxxxxxxxxxx中,top就直接到了顶层页面。所以我没有使用parent.xxxxx给你举例 如果是数组之类的东东可以考虑方案1;如果是字串之类的东东可以考虑方案2;当然,你也可以把数组、JSON之类的数据转为字串格式,从而选用方案2 刚刚验证,发现top.xxx方式访问不到,我是从content页面(也就是同级别的frame)的外部js访问的,top is no defined function ajaxRequest(url, data, callback, type) { alert(bottomBarF.cacheF.validationCache); // if ( jQuery.isFunction( data ) ) { callback = data; data = {}; } return jQuery.ajax({ type: "POST", url: url, data: data, success: function(data) { if(data.success) callback(data); }, dataType: type });};这是contentF框架页面中,外部js调用bottomBarF框架的cacheF框架 显示bottomBarF is not defined 给你个演示吧:1、主框架TOP页 index.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>globe var test</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><SCRIPT LANGUAGE=javascript>var hash={ var1: '1', var2: '2', json: {"id":"topbarF","src":"topbar.html"}, $ : function(id){ return document.getElementById(id); }, doc : function(id){ var _w=document.getElementById(id); var _d=_w.contentDocument||_w.contentWindow.document; return _d; } }</SCRIPT> </head><frameset rows="82,1,*,5" cols="*" frameborder="NO" border="0" framespacing="0"> <frame id="topF" src="top.html" scrolling="NO" noresize marginwidth="0" marginheight="0" frameborder="NO" > <frame id="topbarF" src="topbar.html" scrolling="NO" noresize marginwidth="0" marginheight="0" frameborder="NO" > <frameset id="midF" cols="180,5,*,5,110" frameborder="NO" border="0" framespacing="0"> <frame id="leftF" src="left.html" noresize scrolling="auto" frameborder="NO" marginwidth="0" marginheight="0"> <frame id="leftbarF" src="leftbarswitch.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize BORDERCOLOR="#6699CC"> <frame id="mainF" src="main.html" marginwidth="0" marginheight="0" noresize scrolling="AUTO" frameborder="NO"> <frame id="rightbarF" src="rightbarswitch.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize BORDERCOLOR="#6699CC"> <frame id="rightF" src="right.html" marginwidth="0" marginheight="0" noresize scrolling="AUTO" frameborder="NO"> </frameset> <frame id="bottomF" src="bottom.html" marginwidth="0" marginheight="0" scrolling="NO" frameborder="NO" noresize></frameset><noframes><body bgcolor="#FFFFFF" text="#000000">您的浏览器不支持框架</body></noframes> </html>2、left.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>test</title><style type="text/css">*{ padding:0; margin:0; font-size:14px; font-family:Arial, Helvetica, sans-serif; color:blue;}body{background-color:#ccc; }li{cursor:pointer;margin:15px}</style><script type="text/javascript"> var doc=top.hash.doc;var $=function(id){ return document.getElementById(id); }function getData(id){ var o=doc('bottomF').getElementById(id); doc('mainF').getElementById('show').innerHTML+="<span>一级框架总数</span>:<span>"+o.value+"<span><br>";}function getGlobeVarData(id){ var _type=typeof eval(id); var _data=_type=='String'?_data:_type.toString(); doc('mainF').getElementById('show').innerHTML+="<span>公共变量"+id.replace('top.hash','')+"</span>:<span>"+_data+"<span><br>";}</script></head><body><div id='a'> <ul> <li onclick="getData('numFrame')">获取隐藏域数据</li> <li onclick="getGlobeVarData('top.hash.json')">获取公共变量</li> <li onclick="getGlobeVarData('top.hash.json')">获取公共变量</li> </ul><div></body></html>3、bottom.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>test</title><style type="text/css">*{ padding:0; margin:0; font-size:12px; font-family:Arial, Helvetica, sans-serif;}body{background-color:#CCC;}</style><script type="text/javascript">window.onload=function(){ document.getElementById('numFrame').value=top.frames.length;}</script></head><body><input type="hidden" id='numFrame' /></body></html>4、main.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>test</title><!--script src="http://code.jquery.com/jquery-latest.min.js" ></script--><style type="text/css">*{ font-size:12px;}body{ margin:0; padding:0; font-family:Arial, Helvetica, sans-serif; background-color:#fff; }span {width:100px; background:yellow; margin:20px}</style><script type="text/javascript"></script></head><body><div id='show'></div></body></html>5、right.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>test</title><style type="text/css">*{ padding:0; margin:0; font-size:12px; font-family:Arial, Helvetica, sans-serif;}body{background-color:#ccc; }</style><script type="text/javascript"></script></head><body><iframe id="r" src="righttest.html" ></iframe></body></html>6、righttest.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>test</title><style type="text/css">*{ padding:0; margin:0; font-size:14px; font-family:Arial, Helvetica, sans-serif; color:blue;}body{background-color:#fff; }li{cursor:pointer;margin:15px}</style><script type="text/javascript"> var doc=top.hash.doc;var $=function(id){ return document.getElementById(id); }function getData(id){ var o=doc('bottomF').getElementById(id); doc('mainF').getElementById('show').innerHTML+="<span>一级框架总数</span>:<span>"+o.value+"<span><br>";}function getGlobeVarData(id){ var _type=typeof eval(id); var _data=_type=='String'?_data:_type.toString(); doc('mainF').getElementById('show').innerHTML+="<span>公共变量"+id.replace('top.hash','')+"</span>:<span>"+_data+"<span><br>";}</script></head><body>这是二级框架网页<div id='a'> <ul> <li onclick="getData('numFrame')">获取隐藏域数据</li> <li onclick="getGlobeVarData('top.hash.json')">获取公共变量1</li> <li onclick="getGlobeVarData('top.hash.doc')">获取公共变量2</li> </ul><div></body></html> 你是上天派来救我的么,我以为top指的是top框架,原来top是dom对象 关于浏览器的使用 关于连接的JS不工作的问题 如何实现一个链接只能从某一特定页面点击进去才有效 求教 EXT GRID 禁用 隱藏列 怎样隐藏横向滚动条? 这样的js写法有没有产生闭包? 从远程html获取xml,得到nodetree? 这里的this指的是什么 怎样使事件只被处理一次,即第一次被处理后就禁止它 对csdn论坛的一点点技术上的改进(关于tacontent.htc的绑定问题),欢迎讨论。 获取textarea中的元素 [求助]onclick与onmouseover的不同之处
1、JS实现:
在TOP页面:
<script>
var itparadise=false;
var toury=false;
//这两个变量就可以实现你的需求
</script>
当子页面加载时:
<script>
//改变父页面的全局变量
top.itparadise=location.href
top.toury=true;
</script>2、隐藏域实现:在某个frame(比如id='aaa')中设置隐藏域:
<script>
window.onload=function(){
document.getElementById("itparadise").value="1234567"
document.getElementById("toury").value="保存你的数据"
}
</script>
<input type='hidden' id="itparadise" />
<input type='hidden' id="toury" />这样,可在其他的frame页面中取值:
var aaa=top.document.getElementById("aaa").document.getElementById("itparadise").value
var bbb=top.document.getElementById("aaa").document.getElementById("toury").value
可通过服务端的session()或application()保存一样不经常变化的数据,客户端需要时,只要
var aaa='<%=session("xxx")%>' 这样的形式就可以获得
如果是字串之类的东东可以考虑方案2;当然,你也可以把数组、JSON之类的数据转为字串格式,从而选用方案2
function ajaxRequest(url, data, callback, type) {
alert(bottomBarF.cacheF.validationCache);
//
if ( jQuery.isFunction( data ) ) {
callback = data;
data = {};
} return jQuery.ajax({
type: "POST",
url: url,
data: data,
success: function(data) {
if(data.success)
callback(data);
},
dataType: type
});
};
这是contentF框架页面中,外部js调用bottomBarF框架的cacheF框架
1、主框架TOP页 index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>globe var test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE=javascript>
var hash={
var1: '1',
var2: '2',
json: {"id":"topbarF","src":"topbar.html"},
$ : function(id){
return document.getElementById(id);
}, doc : function(id){
var _w=document.getElementById(id);
var _d=_w.contentDocument||_w.contentWindow.document;
return _d;
}
}</SCRIPT>
</head><frameset rows="82,1,*,5" cols="*" frameborder="NO" border="0" framespacing="0">
<frame id="topF" src="top.html" scrolling="NO" noresize marginwidth="0" marginheight="0" frameborder="NO" >
<frame id="topbarF" src="topbar.html" scrolling="NO" noresize marginwidth="0" marginheight="0" frameborder="NO" >
<frameset id="midF" cols="180,5,*,5,110" frameborder="NO" border="0" framespacing="0">
<frame id="leftF" src="left.html" noresize scrolling="auto" frameborder="NO" marginwidth="0" marginheight="0">
<frame id="leftbarF" src="leftbarswitch.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize BORDERCOLOR="#6699CC">
<frame id="mainF" src="main.html" marginwidth="0" marginheight="0" noresize scrolling="AUTO" frameborder="NO">
<frame id="rightbarF" src="rightbarswitch.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize BORDERCOLOR="#6699CC">
<frame id="rightF" src="right.html" marginwidth="0" marginheight="0" noresize scrolling="AUTO" frameborder="NO">
</frameset>
<frame id="bottomF" src="bottom.html" marginwidth="0" marginheight="0" scrolling="NO" frameborder="NO" noresize>
</frameset>
<noframes><body bgcolor="#FFFFFF" text="#000000">您的浏览器不支持框架</body></noframes>
</html>2、left.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title><style type="text/css">
*{ padding:0; margin:0; font-size:14px; font-family:Arial, Helvetica, sans-serif; color:blue;}
body{background-color:#ccc; }
li{cursor:pointer;margin:15px}
</style>
<script type="text/javascript">
var doc=top.hash.doc;
var $=function(id){ return document.getElementById(id); }function getData(id){
var o=doc('bottomF').getElementById(id);
doc('mainF').getElementById('show').innerHTML+="<span>一级框架总数</span>:<span>"+o.value+"<span><br>";
}function getGlobeVarData(id){
var _type=typeof eval(id);
var _data=_type=='String'?_data:_type.toString();
doc('mainF').getElementById('show').innerHTML+="<span>公共变量"+id.replace('top.hash','')+"</span>:<span>"+_data+"<span><br>";
}</script>
</head><body>
<div id='a'>
<ul>
<li onclick="getData('numFrame')">获取隐藏域数据</li>
<li onclick="getGlobeVarData('top.hash.json')">获取公共变量</li>
<li onclick="getGlobeVarData('top.hash.json')">获取公共变量</li>
</ul>
<div>
</body>
</html>
3、bottom.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title><style type="text/css">
*{ padding:0; margin:0; font-size:12px; font-family:Arial, Helvetica, sans-serif;}
body{background-color:#CCC;}
</style>
<script type="text/javascript">
window.onload=function(){
document.getElementById('numFrame').value=top.frames.length;
}
</script>
</head><body>
<input type="hidden" id='numFrame' />
</body>
</html>4、main.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<!--script src="http://code.jquery.com/jquery-latest.min.js" ></script-->
<style type="text/css">
*{ font-size:12px;}
body{ margin:0; padding:0; font-family:Arial, Helvetica, sans-serif; background-color:#fff; }
span {width:100px; background:yellow; margin:20px}
</style>
<script type="text/javascript"></script>
</head><body>
<div id='show'></div>
</body>
</html>5、right.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title><style type="text/css">
*{ padding:0; margin:0; font-size:12px; font-family:Arial, Helvetica, sans-serif;}
body{background-color:#ccc; }
</style>
<script type="text/javascript"></script>
</head><body>
<iframe id="r" src="righttest.html" ></iframe>
</body>
</html>6、righttest.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title><style type="text/css">
*{ padding:0; margin:0; font-size:14px; font-family:Arial, Helvetica, sans-serif; color:blue;}
body{background-color:#fff; }
li{cursor:pointer;margin:15px}
</style>
<script type="text/javascript">
var doc=top.hash.doc;
var $=function(id){ return document.getElementById(id); }function getData(id){
var o=doc('bottomF').getElementById(id);
doc('mainF').getElementById('show').innerHTML+="<span>一级框架总数</span>:<span>"+o.value+"<span><br>";
}function getGlobeVarData(id){
var _type=typeof eval(id);
var _data=_type=='String'?_data:_type.toString();
doc('mainF').getElementById('show').innerHTML+="<span>公共变量"+id.replace('top.hash','')+"</span>:<span>"+_data+"<span><br>";
}</script>
</head><body>
这是二级框架网页
<div id='a'>
<ul>
<li onclick="getData('numFrame')">获取隐藏域数据</li>
<li onclick="getGlobeVarData('top.hash.json')">获取公共变量1</li>
<li onclick="getGlobeVarData('top.hash.doc')">获取公共变量2</li>
</ul>
<div>
</body>
</html>