通过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

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

查看所有标签

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

Elements of Programming

Elements of Programming

Alexander A. Stepanov、Paul McJones / Addison-Wesley Professional / 2009-6-19 / USD 39.99

Elements of Programming provides a different understanding of programming than is presented elsewhere. Its major premise is that practical programming, like other areas of science and engineering, mus......一起来看看 《Elements of Programming》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

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

在线图片转Base64编码工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具