是这样的,现有也个页面a.htm,我想得到每一个访问a.htm页面的url;
用document.referrer,在得不到值;
链接到a.htm页面的形式可能有<a href>,window.open,window.location.href....请高手帮忙,如何得到上一级url
用document.referrer,在得不到值;
链接到a.htm页面的形式可能有<a href>,window.open,window.location.href....请高手帮忙,如何得到上一级url
在a页面中,request("url")就的到了
window.top.search
可以用parent.document.location
或者 opener.document.location
然后在b.htm中:用window.parent.document.referrer即可得到“a.htm”;但是window.parent.document.referrer只能得到<a>的url,如果用window.location.href...等其他形式链接的话就得不到值更全面的解法正在寻找,暂不结贴,如果有更好的方法,希望大家一起分享,先谢过大家了
js:function goChild()
{
window.location.href="b.htm";
}这样的话在b.htm页面里面用window.parent.document.referrer输出为空;
你说的那种情况是在用a.htm?url=.....传递参数,然后在b.htm页面里面接收吧?
获者改成用服务器端获取
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新建文本文档</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312"/>
</head> <body>
<a href="index.html">连接过去</a>
</body>
</html>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>网站公告</title>
<style type="text/css">
html,body{ text-align:center;}
</style>
</head>
<body>
<script type="text/javascript">
<!--
alert(document.referrer)
//-->
</script>
</body>
</html>
就这两个文件就可以了,注意要建立一个站点。不要直接双击打开href.html,而是通过使用http://localhost/href.html的方式,来访问,然后跳转到index.html的时候,就可以获取到上一个页的路径
alert(window.opener.location.href);
}else if(window.parent){
alert(window.parent.location.href);
}else{
alert("没有parent页面");
}