js得到当前页面的url信息
所有的代码都是可用,而且附了图片的,不过是直接用我自己的文章地址,所以有些显示的有点奇怪。
大家可以找个网址试试代码是否可行。
1,设置或获取对象指定的文件名或路径。
console.log(window.location.pathname)

2,设置或获取整个 URL 为字符串。
console.log(window.location.href);

3,设置或获取与 URL 关联的端口号码。
console.log(window.location.port)

4,设置或获取 URL 的协议部分。
console.log(window.location.protocol)

5,设置或获取 href 属性中在井号“#”后面的分段。
console.log(window.location.hash)

6,设置或获取 location 或 URL 的 hostname 和 port 号码。
console.log(window.location.host)

7,设置或获取 href 属性中跟在问号后面的部分。
console.log(window.location.search)

8,获取变量的值(截取等号后面的部分)
var url = window.location.search;
console.log(JSON.stringify(url));
console.log(url.length);
console.log(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length); console.log(loc);

9,用来得到当前网页的域名
console.log( document.domain);

js得到当前页面的url信息的更多相关文章
- js得到当前页面的url信息方法
js得到当前页面的url信息方法:http://www.cnblogs.com/zuosong160522/p/5755615.html js获取url传递参数,js获取url?后面的参数:http: ...
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或 ...
- JS获取当前页面的URL信息
设置或获取对象指定的文件名或路径. <script> alert(window.location.pathname) </script> 设置或获取整个 URL 为字符串. & ...
- js获取当前页面的url信息方法
例如网址:http://localhost:12085/My/OrderM.aspx 设置或获取对象指定的文件名或路径. alert(window.location.pathname) 输出结果:/M ...
- 怎样用js得到当前页面的url信息方法(JS获取当前网址信息)
设置或获取对象指定的文件名称或路径.window.location.pathname 设置或获取整个 URL 为字符串.window.location.href; 设置或获取与 URL 关联的端口号码 ...
- 如何用js得到当前页面的url信息方法
设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或 ...
- js获取当前页面的URL并且截取?之后的数据,返回json
js获取当前页面的URL并且截取'?'之后的数据,返回json格式的数据 最近想要把学到的东西整理一下,以后方便查找,也是一种自我累积,如果有错误或者更好的,欢迎提出! 这篇文档主要是写关于获取页面的 ...
- 获取当前页面的URL信息
以前在做网站的时候,经常会遇到当前页的分类高亮显示,以便让用户了解当前处于哪个页面.之前一直是在每个不同页面写方法.工程量大,也不便于修改.一直在想有什么简便的方法实现.后来在网上查到可以用获取当前U ...
- js获取当前页面的url网址信息小汇总
在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结. 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblog ...
随机推荐
- C/C++ 混合编程
[面试] C/C++ 语法(五) -- extern 1. C 调用 C++ 开发的DLL库 C和C++混合编程(__cplusplus 与 external "c" 的使用) # ...
- Early Media and Music on Hold
Early media refers to any media that is played to the initial caller’s phone before the remote party ...
- 【bzoj1232】[Usaco2008Nov]安慰奶牛cheer
问题描述 Farmer John变得非常懒,他不想再继续维护供奶牛之间供通行的道路.道路被用来连接N个牧场,牧场被连续地编号为1到N.每一个牧场都是一个奶牛的家.FJ计划除去P条道路中尽可能多的道路, ...
- TX-
NVIDIA Jetson TX2刷机 TX1 Gsteramer 环境配置 TX1 ssh配置
- zend studio 10.6.2破解和汉化
破解文件下载地址 http://dldx.csdn.net/fd.php?i=881874911175745&s=b2f091d89f675e30c36dcc00c4cd2702 下载破解 ...
- C# 32位程序在64位系统下运行中解决重定向问题
在64位的Windows操作系统中,为了兼容32位程序的运行,64位的Windows操作系统采用重定向机制.目的是为了能让32位程序在64位的操作系统不仅能操作关键文件文夹和关键的注册表并且又要避免与 ...
- 创建Maven项目步骤
(转自:http://blog.csdn.net/chuyuqing/article/details/28879477) 使用eclipse插件创建一个web project 首先创建一个Maven的 ...
- 3、scala数组
一.Array .Array Buffer 1.Array 在Scala中,Array代表的含义与Java中类似,也是长度不可改变的数组. 此外,由于Scala与Java都是运行在JVM中,双方可以互 ...
- Updatepanel 中使用 Timer 控件 失去焦点问题
在Update Panel 中 如果使用timer 定时刷新数据,会造成textbox 或者其他控件的焦点丢失问题. 所以 text box 不能和timer 放在同一个Updatepanel 中. ...
- 无法搜索联机扩展 因为尝试与服务器联系 Visual studio 怎么解决?
根目录: devenv.exe.config 编辑: 修改如下即可: <system.net> <defaultProxy useDefaultCredentials="t ...