获取当前页面的主机/端口号/路径

来源:互联网 发布:淘宝上卖自制食品条件 编辑:程序博客网 时间:2024/05/21 20:22



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

window.location.href

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

window.location.protocol

3、设置或获取 URL 的主机和端口

window.location.host

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

window.location.port

5、设置或获取与 URL 的文件路径(就是文件地址)

window.location.pathname

6、设置或获取 href 属性中跟在问号后面的部分(搜索内容)

window.location.search

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

window.location.hash


打开一个新页面 window.open(url);

在当前页面打开新页面:window.location.href = url;


原创粉丝点击