123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script>
- /**
- * History
- * -对象,可以用来操作浏览器向前或向后翻页
- */
- /**
- * length
- * -属性,可以获取到当前访问的链接数量
- */
- // alert(history.length);
- window.onload = function () {
- //获取按钮对象
- var btn = document.getElementById('btn');
- btn.onclick = function () {
- /**
- * length
- * -属性,可以获取到当前访问的链接数量
- */
- // alert(history.length);
- /**
- * back()
- * -方法,可以回退到上一个页面,作用和浏览器的回退按钮一样
- */
- // history.back();
- /**
- * forward()
- * -可以跳转到下一个页面,作用和浏览器的前进按钮一样
- */
- // history.forward();
- /**
- * go()
- * -可以用来跳转到指定的页面
- * -它需要一个整数作为参数
- * 1:表示向前跳转一个页面,相当于forward()
- * 2:表示向前跳转两个页面
- * -1:表示向后跳转一个页面,相当于back()
- * -2:表示向后跳转两个页面
- */
- history.go(-2);
- };
- };
- </script>
- </head>
- <body>
- <button id="btn">点一下</button>
- <h1>History</h1>
- <a href="02.BOM.html">去BOM</a>
- </body>
- </html>
|