企业网站管理系统 开源宁波百度关键词推广
history对象保存了当前浏览器窗口中打开页面的一个历史记录列表,使用history对象可以将当前浏览器页面跳转到某个曾经打开过的页面。
1.back()方法
后退一个页面,相当于浏览器的后退按钮。
//语法:
//history.back();
<body><input id="back" type="button" value="后退"/><script type="text/javascript">document.getElementById("back").onclick = his;function his(){history.back();}</script>
</body>
2.forward()方法
前进一个页面,相当于浏览器前进按钮。
//语法:
//history.forward();
<body><input type="forward" type="button" value="前进"/><script type="text/javascript">document.getElementById("forward").onclick = his;function his(){history.forward();}</script>
</body>
3.go()方法
打开一个指定位置的页面。
//语法:
//history.go(number);
//number 可为任意整数。当number>0时,打开历史记录表中位于当前页面之前的第number个页面;反之,当number<0时,打开历史记录表中位于当前页面之后的第number个页面。
<body><input id="goBack" type="button" value="前进"/><input id="goForward" type="button" value="后退"/><script type="text/javascript">document.getElementById("goBack").onclick = hisBack;document.getElementById("goForward").onclick = hisForward;function hisBack(){history.go(-1);}function hisForward(){history.go(1);}</script>
</body>
tips:
在history对象中,可以分别使用history.go(1)和history.go(-1)代替history.forward()和history.back()。用户在当前页面之前或之后必须要有可访问的页面才能实现跳转,否则不显示效果。
————————————————
版权声明:
原文链接:https://blog.csdn.net/weixin_46990454/article/details/111224510