通过js获取当前页面url的信息

栏目: JavaScript · 发布时间: 7年前

内容简介:在web前端制作中,可以通过javascript获取当前网页url的相关信息,整理如下:1、设置或获取对象指定的文件名或路径2、设置或获取整个URL为字符串

在web前端制作中,可以通过javascript获取当前网页url的相关信息,整理如下:

1、设置或获取对象指定的文件名或路径

window.location.pathname

2、设置或获取整个URL为字符串

window.location.href

3、设置或获取与URL关联的端口号

window.location.port

4、设置或获取URL的协议部分

window.location.protocol

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

window.location.hash

6、设置或获取location或URL的hostname和port号码

window.location.host

7、设置或获取href属性中跟在问号后面的部分

window.location.search

8、获取变量的值(截取等号后面的部分)

var url = window.location.search;
alert(url.length);
alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);

9、获取当前网页的域名

document.domain

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Producing Masculinity

Producing Masculinity

Michele White / Routledge / 2019-3 / $39.95

Thoughtful, witty, and illuminating, in this book Michele White explores the ways normative masculinity is associated with computers and the Internet and is a commonly enacted online gender practice. ......一起来看看 《Producing Masculinity》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具