zoukankan      html  css  js  c++  java
  • history对象的使用--JavaScript基础

    history对象提供与历史清单有关的信息,包含最经访问过的10个网页的URL

    1、history对象常用属性

    length 返回浏览器历史列表中URL数量

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>history对象的length属性</title>
    </head>
    <body>
    </body>
    <script>
      document.write("<li>"+history.length);
    </script>
    </html>

    2、history对象常用方法

    1)back()方法

     该方法的功能是在浏览器中显示上一页,相当于go(-1)

    firstPage.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>这是第一个页面</title>
    </head>
    <body>
      <span>这是第一个页面</span>
      <a href="secondPage.html">去上第二个页面</a>
    </body>
    </html>

    secondPage.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>这是第二个页面</title>
    </head>
    <body>
      <span>这是第二个页面</span>
      <p><a href="#" onclick="Javascript:window.history.back()">back()返回到上个页面</a></p>
      <p><a href="#" onclick="Javascript:window.history.go(-1)">go(-1)返回到上个页面</a></p>
    </body>
    </html>

    图示:

     

    2)forward()方法

    该方法的功能是在浏览器中显示下一页,相当于go(1)

    3)go(int)方法

     该方法的功能是在浏览器中载入从当前算起的第int个页面(int为整数),如果int为负,表示往回,相当于返回。

  • 相关阅读:
    04.安全-TLS1.2连接过程
    02.安全-证书和CA
    01.安全-加密
    00.https基本
    00.二叉树基本
    二分查找01.基本二本查找及其变种
    01.数据结构资料,时间复杂度空间复杂度(数据结构算法基本)
    从 CentOS 8 平滑迁移至 CentOS Stream
    identityserver使用记录
    vs2019 使用私钥进行连接时出错 ssh连接报错
  • 原文地址:https://www.cnblogs.com/qikeyishu/p/7601662.html
Copyright © 2011-2022 走看看