html获得当前页面路径

要使HTML获得路径,肯定是要用到JavaScript,获得方式有以下几种方式

获得方式都是   window.location.   = this.location.    在后边加入要获得的方式,这里我就以this.location.方式说一下

假如当前页面的全路径是  http://127.0.0.1:8020/login/getUrl.html?__hbt=1523851552803

1. this.location.href  

    获得全路径  如  http://127.0.0.1:8020/login/getUrl.html?__hbt=1523851552803

2. this.location.search

    获得路径中的参数  如  ?__hbt=1523851552803

3. this.location.protocol

    获得路径的协议  如  http:

4. this.location.host

    获得主机及端口号 如  127.0.0.1:8020

5. this.location.hostname

    获得主机地址 如 127.0.0.1

6. this.location.port

    获得端口号   如  8020

7. this.location.pathname

    获得路径部分 如  /login/getUrl.html


另外还有

  1. url = window.location.hash; /* 获取锚点(“#”后面的分段) */  
  2.             alert(url); /* #test?name=test */

猜你喜欢

转载自blog.csdn.net/qq_40975034/article/details/79959107
今日推荐