zoukankan      html  css  js  c++  java
  • JavaScript 27 Location

    Location表示浏览器中的地址栏

    示例 1 : 

    刷新当前页面

    <span>当前时间:</span>
    <script>
      var d = new Date();
      document.write(d.getHours());
      document.write(":");
      document.write(d.getMinutes());
      document.write(":");
      document.write(d.getSeconds());
      document.write(":");
      document.write(d.getMilliseconds());
     
    function refresh(){
      location.reload();
    }
    </script>
     
    <br>
    <button onclick="refresh()">刷新当前页面</button>

      示例 2 : 

    跳转到另一个页面

    <script>
    function jump(){
      //方法1
      //location="/";
     
      //方法2
      location.assign("/");
       
    }
    </script>
     
    <br>
    <button onclick="jump()">跳转到首页</button>

     示例 3 : 

    Location的其他属性

    <script>
    function p(s){
    document.write(s);
    document.write("<br>");
    }

    p("协议 location.protocol:"+location.protocol);
    p("主机名 location.hostname:"+location.hostname);
    p("端口号 (默认是80,没有即表示80端口)location.port:"+location.port);

    p("主机加端口号 location.host: "+location.host);
    p("访问的路径 location.pathname: "+location.pathname);

    p("锚点 location.hash: "+location.hash);
    p("参数列表 location.search: "+location.search);

    </script>

  • 相关阅读:
    TLPI读书笔记第15章-文件属性2
    TLPI读书笔记第15章-文件属性1
    Java异常及错误
    10055
    4月。
    JavaScript三种方法获取地址栏参数的方法
    页面预加载loading动画,再载入内容
    什么是可串行化MVCC
    简化版扫雷详细解
    论unity中UI工具与GUI函数
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13370124.html
Copyright © 2011-2022 走看看