例如,在1.js中,
var url="${path}/jccAction.do?hxh=jcList&pageNo="+ pageNo+"pagesize="+pagesize+"&stype=ldNumber&key=";
document.frames.iframe_oper.document.location.replace(url);
在该页面中有个<IFRAME id="iframe_oper" src="2.jsp">在2.jsp中有个2.js。
var url2="";
parent.frames.iframe_detail.document.location.replace(url);
如何在URL2=“”中取到从1.js中传来的url呢。
不用split把URL分割,组成数组,重新组合。我想问有没有更加方便和快捷的方法就可以直接取到!
各位大侠们帮帮忙,在线等!
var url="${path}/jccAction.do?hxh=jcList&pageNo="+ pageNo+"pagesize="+pagesize+"&stype=ldNumber&key=";
document.frames.iframe_oper.document.location.replace(url);
在该页面中有个<IFRAME id="iframe_oper" src="2.jsp">在2.jsp中有个2.js。
var url2="";
parent.frames.iframe_detail.document.location.replace(url);
如何在URL2=“”中取到从1.js中传来的url呢。
不用split把URL分割,组成数组,重新组合。我想问有没有更加方便和快捷的方法就可以直接取到!
各位大侠们帮帮忙,在线等!
function getUrlPara(str,name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = str.substr(str.indexOf("\?")+1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
用法: getUrlPara(location.href,"你要的属性")
则该页面的属性值为
document.location.hostname = localhost // 打开页面地址的主机名
document.location.port = 8080 // 打开页面地址的端口号
document.location.pathname = b/a.jsp // 打开页面地址的路径名
document.location.hash = test // 打开页面地址中“#”后面的内容
document.location.search = name=sa&pass=qq#test // 打开页面地址中“?”后面的内容
document.location.href = http://localhost:8080/b/a.jsp?name=sa&pass=qq#test // 打开页面的地址
3楼的方法是获取传来的参数,然后从中获取符合要求的属性,我只想一次直接把js中传来的URL全取到。
期待高手的另外问答
<script>
var url ="xxx"
</script>
<iframe src="test.htm"></iframe>
test.htm<script>
window.onload=function(){
alert(parent.url)
}
</script>
<head>
<script>
var url='';
window.onload=function(){
url="aa.htm";
document.frames.iframe_oper.document.location.replace(url);
}
</script>
</head>
<body>
<IFRAME id="iframe_oper" src="2.htm">
</body>
</html>
==========================================
aa.htm:<script>
alert(location.href)
</script>
<html>
<head>
<script>
window.onload=function(){
var url="aa.htm";
document.frames.iframe_oper.document.location.replace(url);
}
</script>
</head>
<body>
<IFRAME id="iframe_oper" src="2.htm">
</body>
</html>
==========================================
aa.htm:<script>
alert(location.href)
</script>
我是想在2.htm中获取到aa.htm
检查你的document.frames.iframe_oper.document.location.replace(url);中的url是否合法
<head>
<script>
window.onload=function(){
var url="aa.htm";
alert('原值:'+document.frames.iframe_oper.xsxxjsp)
document.frames.iframe_oper.xsxxjsp=url
alert('新值:'+document.frames.iframe_oper.xsxxjsp)
//这个时候2.htm中的xsxxjsp变量(就是url)已经变量,怎么写库就是你的事了,呵呵
}
</script>
</head>
<body>
<IFRAME id="iframe_oper" src="2.htm">
</body>
</html>
==========================================
2.htm
<script>
var xsxxjsp='123'
</script>22222222222222222222222222222
<script>
var xsxxjsp='123'window.setInterval('alert(xsxxjsp)',3000)//加上这个句子就清楚了
//你也可以把alert(xsxxjsp)变成一个函数,检测xsxxjsp的变化,一旦改变就AJAX把xsxxjsp送往后台写库
</script>
你这样做可以动态的取出2.htm中的值。其实正好和我需要的相反了。我是想在2.htm中能够获得1.htm中的URL,因为正如题目中我举得例子一样,在1.htm中url是可以动态变化的,不管1中URL的如何变化在2中都能取到1中的URL,也许你会说把它反过来就行了。但是页面是已经做好了的,是在1.htm中<IFRAME src=2.htm>.然后在2.htm中取1中的URL。在帮帮忙!
<html>
<head>
<script>
var url='';
function SetURL(){
url="aa.htm";
}
SetURL()
</script>
</head>
<body>
<IFRAME id="iframe_oper" src="2.htm">
</body>
</html>
==========================================2.htm:
<script>
var myid=0;
function GetParentURL(){
var xsxxjsp=parent.url;
alert(xsxxjsp);
//下面AJAX把xsxxjsp送往后台写库
window.clearInterval(myid)
// AJAX........... //在AJAX的回调函数里,再回复myid=window.setInterval('GetParentURL()',3000)
//....................
}
window.onload=function(){
myid=window.setInterval('GetParentURL()',3000)
}
</script>2222222222222