• location 对象


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
    // demo : "http://baidu.com/#contents"   返回URL中的hash (#号跟零或多个字符),如果URL中不包含散列,则返回空字符串
    var a = window.location.hash;
    // console.log(a); //#contents
    
    
    // demo :"wwww.baidu.com:80"    返回服务器名称和端口号 (如果有)
    var b = window.location.host;
    console.log(b);
    
    
    // demo : "www.baidu.com"   返回不带端口号的服务器名称
    var c = window.location.hostname
    console.log(x);
    
    
    // demo : "http://www.baidu.com"    返回当前加载页面的完整URL。而location对象的toString()方法也返回这个值
    var d = window.location.href;
    console.log(d);
    
    
    // demo : "/hehe/"  返回URL中的目录和(或)文件名
    var e = window.location.pathname;
    console.log(e);
    
    
    // demo : "808"     返回URL中指定的端口号。如果URL中不包含端口号,则这个属性返回空字符串。
    var f = window.location.port;
    console.log(f);
    
    
    // demo : "http:"   返回页面使用的协议。通常是 http: 或 https:
    var g = window.location.protocol;
    console.log(g);
    
    
    // demo : "?s=javascript"   返回URL的查询字符串。这个字符串以问号开头
    var h = window.location.search;
    console.log(h);
    </script>
    </head>
    <body>
        
    </body>
    </html>
    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    linux-01Red Hat Enterprise Linux 7(RHEL7)配置静态IP地址
    Linux下Tomcat重新启动
    获取root权限
    -save 和 --save-dev的区别
    周五的听歌时间
    十月第二周计划
    国庆计划
    周末计划
    前端基础进阶系列
    前端基础进阶(二):执行上下文详细图解
  • 原文地址:https://www.cnblogs.com/baixc/p/4519199.html
Copyright © 2020-2023  润新知