1. history对象 保存了用户在浏览器中访问页面的历史记录
  2. 语法:history.back()
  3. 功能:回到历史记录的上一步
  4. 相当于是用了history.go(-1)
  5. //-1表示前一步,-2前两部
  6. 语法:history.go(1)
  7. 功能:回到历史记录的前一步
  8. 相当于history.forward()
  9. 语法:history.go(-n)
  10. 功能:回到历史记录的前n
  11. 语法:history.go(n)
  12. 功能:回到历史记录的后n

4-1html文件

  1. <p>06</p>
  2. <a href="07-history对象.html">07.html</a>
  3. </body>

4-2 history对象.html文件

  1. <p>07</p>
  2. <button id="btn">btn</button>
  3. <script>
  4. var btn = document.getElementById("btn")
  5. btn.onclick = function(){
  6. history.back(); // 回到历史记录的上一步
  7. }
  8. </script>