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);

  • 相关阅读:
    vue实现通过链接跳转到页面
    vue-cli2-项目的创建
    平均数
    Spring-Spring简介
    vue + element-ui 表单校验封装公用方法
    Python(一)数据结构和算法的20个练习题问答
    Python包中__init__.py作用
    if __name__=="__main__":
    execute immediate
    oracle基础知识过一遍(原创)
  • 原文地址:https://www.cnblogs.com/ydymz/p/9378263.html
Copyright © 2011-2022 走看看