js获取来源网址

举例: 
1. a.html文件内容如下: 
<a href="b.html">浏览b.html </a> 
2. b.html文件中的内容如下: 
<body> 
<script type="text/javascript"> 
document.write(document.referrer); 
</script> 
</body>

3. 则在通过a.html中的超链接访问b.html的时候,显示的结果是: 
http://127.0.0.1:8180/a.html

说明:

经过测试,需要将两个文件放在服务器中才能得到想要的结果,若直接在本地文件夹中则得到空字符串,若直接在浏览器地址栏中输入b.html的URL地址或使用打开菜单访问b.html,则document.referrer的值为空字符串。

时间: 2024-08-25 16:27:26

js获取来源网址的相关文章

PHP &amp;&amp; JS获取当前网址

一:JS实现 top.location.href 顶级窗口的地址 this.location.href 当前窗口的地址 二:PHP实现 #测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br>"; #localhost //获取网页地址 echo $_SERVER['PHP_SELF']."<br>"; #/blog/t

如何用js得到当前页面的url信息方法(JS获取当前网址信息)

设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或获取与 URL 关联的端口号码. alert(window.location.port) 设置或获取 URL 的协议部分. alert(window.location.protocol) 设置或获取 href 属性中在井号“#”后面的分段. alert(window.location.hash) 设

js得到当前页面的url信息方法(JS获取当前网址信息)

1.设置或获取整个 URL 为字符串: window.location.href 2.设置或获取与 URL 关联的端口号码: window.location.port 3.设置或获取 URL 的协议部分 window.location.protocol 4.设置或获取 href 属性中跟在问号后面的部分 window.location.search 5.获取变量的值(截取等号后面的部分) var url = window.location.search;//    alert(url.lengt

js获取当前页面url网址等信息

使用js获取当前页面的url网址信息. 1.设置或获取整个 URL 为字符串: window.location.href 2.设置或获取与 URL 关联的端口号码: window.location.port 3.设置或获取 URL 的协议部分 window.location.protocol 4.(www.jbxue.com)设置或获取 href 属性中跟在问号后面的部分 window.location.search 5.获取变量的值(截取等号后面的部分) var url = window.lo

js 获取当前页url网址信息

转载地址:js如何准确获取当前页面url网址信息 摘录: 举例一个URL,然后获得它的各个组成部分:http://i.cnblogs.com/EditPosts.aspx?opt=1 1.window.location.href(设置或获取整个 URL 为字符串) var test = window.location.href; alert(test);返回:http://i.cnblogs.com/EditPosts.aspx?opt=1 2.window.location.protocol(

js获取当前页面的url网址信息小汇总

在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结. 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblogs.com/EditPosts.aspx?opt=1 1.window.location.href(设置或获取整个 URL 为字符串) var test = window.location.href; alert(test); 返回:http://i.cnblogs.com/EditPosts.as

js 获取当前的网址

js 获取当前的网址http://www.xcx.cc/index.php/home/index/ind?idf=12321var $cur_url=window.location.href; //获取全部的网址var $psurl = window.location.pathname; // 获取 index.php/home/index/ind var $par = window.location.search; //获得 ?idf=12333var test = window.locati

使用JS准确获取URL网址中参数的几种方法

记录下使用JS准确获取URL网址中参数的方法: 参考链接1. https://blog.csdn.net/Zhihua_W/article/details/54845945?utm_source=blogxgwz9 2.https://blog.csdn.net/william_jzy/article/details/84942781 原文地址:https://www.cnblogs.com/lwming/p/10954725.html

js判断访客来源网址和关键字

加入现在有A.B两个站,A为友站,B为我站. 希望判断使用从A站连来时,就把访问者拒绝在门外,只要用简单几行的javascript,就可抓到使用的来源,以及作出一些防范的措施. <script type="text/javascript"> var refurl=document.referrer; if(refurl.indexOf("wowgame")>-1){ alert("你的来源网址为:["+document.refe