博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jquery获取当前页面的URL信息
阅读量:7211 次
发布时间:2019-06-29

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

   在上一篇中,笔者跟大家提到了如何使用location.search来获取URL地址?后面的内容,本篇博客将聚焦于如何使用jquery获取当前页面的URL地址信息。

一.设置或获取对象指定的文件名或路径:就是获取端口和?之间的文件名或者路径,看下图就明白了:

window.location.pathname例:http://localhost:8086/topic/index?topicId=361alert(window.location.pathname); 则输出:/topic/index

 

二. 设置或获取整个 URL 为字符串。

window.location.href例:http://localhost:8086/topic/index?topicId=361alert(window.location.href); 则输出:http://localhost:8086/topic/index?topicId=361

三.设置或获取与 URL 关联的端口号码

window.location.port例:http://localhost:8086/topic/index?topicId=361alert(window.location.port); 则输出:8086

四.设置或获取 URL 的协议部分:

window.location.protocol例:http://localhost:8086/topic/index?topicId=361alert(window.location.protocol); 则输出:http:

五.设置或获取 href 属性中在井号“#”后面的分段:

使用window.location.hash方法即可

六.设置或获取与 URL 关联的端口号码:

window.location.port例:http://localhost:8086/topic/index?topicId=361alert(window.location.port); 则输出:8086

七.设置或获取 location 或 URL 的 hostname 和 port 号码:说白了就是获取主机和端口

window.location.host例:http://localhost:8086/topic/index?topicId=361alert(window.location.host); 则输出:http:localhost:8086

八.设置或获取 href 属性中跟在问号后面的部分:

例:http://localhost:8086/topic/index?topicId=361alert(window.location.search); 则输出:?topicId=361

最后做一个总结:

 

转载于:https://www.cnblogs.com/pyspark/p/8166539.html

你可能感兴趣的文章
get_magic_quotes_gpc()函数用法介绍
查看>>
svn客户端的使用
查看>>
UITableview高度计算
查看>>
WebSocket
查看>>
Linux防火墙-SELinux、netfilter、iptables、ifconfig
查看>>
服务器变量:$_SERVER
查看>>
OSSIM中快速部署HIDS
查看>>
WebSocket科普
查看>>
java23中设计模式——行为模式——Chain of Responsibility(职责链)
查看>>
我的 intellij idea 设置
查看>>
【Java并发性和多线程】Java中的锁
查看>>
2018 前端开发框架对比
查看>>
今天工作
查看>>
substring,indexof,charAt区别
查看>>
2016OSC源创会年终盛典-架构与数据专场-杨亮
查看>>
Java什么时候提高境界支持async/await写法啊?
查看>>
自定义序列化和反序列化的java实现
查看>>
遇到:"ORA-27121: UNABLE TO DETERMINE SIZE OF SHAR...
查看>>
2014 年度 Git@OSC 最热门的 50 个项目
查看>>
Kafka源码分析-序列3 -Producer -Java NIO(Reactor VS Peactor)
查看>>