博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于地址栏url的一些小结
阅读量:6983 次
发布时间:2019-06-27

本文共 1113 字,大约阅读时间需要 3 分钟。

1.获取整个地址栏地址

//获取整个地址栏地址     var href = window.location.href;     console.log(href);

以上代码就是获取整个url地址

2.获取url协议部分

//获取url协议部分     var protocol = window.location.protocol;     console.log(protocol);

如果url为,则window.location.protocol就是http:

3.获取主机部分

//获取主机部分(带端口号)    var host = window.location.host;    console.log(host);

如果url为,或者url地址为:1111/test/test.html,则window.location.host为192.1.1.1:1111如果有端口号,端口号也是要带上的

//获取主机部分(不带端口号)    var hostname = window.location.hostname;    console.log(hostname);

url地址为:1111/test/test.html,则hostname为192.1.1.1

4.获取端口号

//获取端口号    var port = window.location.port;    console.log(port);

url地址为:1111/test/test.html,则window.location.port为1111

5.获取url部分路径

//获取部分路径    var pathname = window.location.pathname;    console.log(pathname);

url地址为:1111/test/test.html?a=1,则window.location.pathname为/test/test.html,也就是主机部分后面到参数部分前面的就是pathname

6.获取url参数部分

//参数部分    var search = window.location.search;    console.log(search);

url地址为:1111/test/test.html?a=1&b=2,则search值为?a=1&b=2

7.获取锚点

//获取锚点    var hash = window.location.hash;    console.log(hash);

url地址为:1111/test/test.html?a=1&b=2#1,则hash为#1

转载地址:http://gltpl.baihongyu.com/

你可能感兴趣的文章
Bash 中的特殊字符大全
查看>>
《C语言点滴》一1.5 内功修炼
查看>>
浅析 Linux 初始化 init 系统: UpStart
查看>>
《PHP和MySQL Web开发从新手到高手(第5版)》一1.7 万事俱备,摩拳擦掌
查看>>
【Hadoop Summit Tokyo 2016】LLAP:Hive上的次秒级分析查询
查看>>
倚天遇到屠龙:LightGBM VS xgboost谁才是最强的梯度提升库?
查看>>
snownlp 中文语法分析
查看>>
Python中os和shutil模块实用方法集锦
查看>>
c++中的左值与右值
查看>>
阿里云推出免费套餐 30余款云产品半年免费
查看>>
linux 用户/用户组添加修改删除(ubuntu/centos)
查看>>
Flink 原理与实现:Window 机制
查看>>
Kubernetes环境下的各种调试方法
查看>>
CC2530之Flash笔记
查看>>
Weex Workshop 挑战赛,等你来战!
查看>>
linux 怎么完全卸载mysql数据库
查看>>
Dart的HTTP请求和响应(1)
查看>>
寻找最大的K个数,Top K问题的堆实现
查看>>
自动发布工具应该具备的11个标准特征
查看>>
页面设计四大基本原则
查看>>