返回当前文档的文档的url

时间:2023-03-09 19:33:56
返回当前文档的文档的url
 HTML DOM referrer 属性
HTML DOM Document 对象 定义和用法
referrer 属性可返回载入当前文档的文档的 URL。 语法
document.referrer
说明
如果当前文档不是通过超级链接访问的,则为 null。这个属性允许客户端 JavaScript 访问 HTTP 引用头部。 实例
<html>
<body> The referrer of this document is:
<script type="text/javascript">
document.write(document.referrer)
</script> </body>
</html>
 [html] view plain copy
var prevLink = document.referrer;
if($.trim(prevLink)==''){
location.href = 'www.example.com/index.html';
}else{
if(prevLink.indexOf('www.example.com')==-1){ //来自其它站点
location.href = 'www.example.com/index.html';
}
if(prevLink.indexOf('register.html')!=-1){ //来自注册页面
location.href = 'www.example.com/index.html';
}
location.href = prevLink;
}