码迷,mamicode.com
首页 > 编程语言 > 详细

history对象的使用--JavaScript基础

时间:2017-09-27 16:15:08      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:har   char   onclick   浏览器   rip   cond   logs   --   显示   

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为负,表示往回,相当于返回。

history对象的使用--JavaScript基础

标签:har   char   onclick   浏览器   rip   cond   logs   --   显示   

原文地址:http://www.cnblogs.com/qikeyishu/p/7601662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!