zoukankan      html  css  js  c++  java
  • js得到当前页面的url信息

    所有的代码都是可用,而且附了图片的,不过是直接用我自己的文章地址,所以有些显示的有点奇怪。

    大家可以找个网址试试代码是否可行。

    1,设置或获取对象指定的文件名或路径。

    console.log(window.location.pathname)

    2,设置或获取整个 URL 为字符串。

    console.log(window.location.href);

    3,设置或获取与 URL 关联的端口号码。

    console.log(window.location.port)

    4,设置或获取 URL 的协议部分。

    console.log(window.location.protocol)

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

    console.log(window.location.hash)


    6,设置或获取 location 或 URL 的 hostname 和 port 号码。

    console.log(window.location.host)

    7,设置或获取 href 属性中跟在问号后面的部分。

    console.log(window.location.search)


    8,获取变量的值(截取等号后面的部分)

     var url = window.location.search;
     console.log(JSON.stringify(url));
     console.log(url.length);
     console.log(url.lastIndexOf('='));
     var loc = url.substring(url.lastIndexOf('=')+1, url.length);
    
     console.log(loc);


    9,用来得到当前网页的域名

    console.log( document.domain);

  • 相关阅读:
    CF949C Data Center Maintenance 题解
    P1438 无聊的数列 题解
    CF620E New Year Tree 题解
    结构体优先队列的定义
    CF464E The Classic Problem 题解
    CF427C Checkposts
    CF161D Distance in Tree 题解
    P4375 [USACO18OPEN]Out of Sorts G 题解
    SCI, SCIE, 和ESCI的区别
    Matlab画图中图的方法
  • 原文地址:https://www.cnblogs.com/ydymz/p/9378263.html
Copyright © 2011-2022 走看看