window. location 获取url各项参数详解

window.location获取url各项参数详解

1.href ----- 整个URL字符串.
2.protocol ----- 含有URL第一部分的字符串,如https.
3.host ----- 主机名.
4.port ----- 端口号.
5.pathname ----- 路径.
6.search ----- “?” 之后的字符串.
7.hash ----- “#” 之后的字符串.

下面举个例子,有这样一个URL

https://www.djhero.com:80/dj/post/0805/dongjing.html?ver=1.0&id=1#happy

1.window.location.href
整个URl字符串(浏览器完整的地址栏)
返回值:http://www.djhero.com:80/dj/post/0805/dongjing.html?ver=1.0&id=6#happy

2.window.location.protocol
URL的协议部分
返回值:https:

3.window.location.host & window.location.hostname
URL的主机部分
返回值:www.djhero.com

4.window.location.port
URL的端口部分
返回值:" "
Note: If the port number is default (80 for http and 443 for https), most browsers will display 0 or nothing.

5.window.location.pathname
URL的路径部分
返回值:/dj/post/0805/dongjing.html

6.window.location.search
查询部分
返回值:?ver=1.0&id=1

7.window.location.hash
锚点
返回值:#happy

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值