首页 |  我的博客 |  查看该博主内容分类 | 

vue获取当前页面地址关于url的相关获取

  • 获取当前页面完整地址:window.location.href

  • 获取前面固定地址:window.location.host

  • 关于window.location的详解:
    window.location 对象不仅可以获得当前页面的地址 (URL),还能够将浏览器重定向到新的页面。
    下面,以http://www.xxxxxx.com:8000/test?id=123&username=xxx为例来进行解释:

    • window.location.href (当前url)—— http://www.xxxxxx.com:8000/test?id=123&username=xxx

    • window.location.protocol(协议)—— http:

    • window.location.host(域名 + 端口)—— www.xxxxxx.com:8000

    • window.location.hostname(域名)—— www.xxxxxx.com

    • window.location.port(端口)—— 8000

    • window.location.pathname(路径)—— /test

    • window.location.search (请求的参数)—— ?id=123&username=xxx

    • window.location.origin(路径前面的url)—— http://www.xxxxxx.com:8000

posted @ 2022-10-22 09:31  Z哎呀  阅读(1154)  评论(0)    收藏  举报