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



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;


猜你喜欢

转载自blog.csdn.net/qq_30629571/article/details/78654535
今日推荐