1、示例
<script>
document.write(history.length);//浏览器历史列表中的 URL 数量
function fan() {
return history.back();
}
function fo() {
return history.forward()
}
function gof() {
return history.go(-1);
}
function gof2() {
return history.go(1);
}
function gof1() {
return history.go(-2);
}
</script>
<button type="button" onclick="fan()">返回</button>
<button type="button" onclick="fo()">前进</button>
<button type="button" onclick="gof()">go(-1)返回一页</button>
<button type="button" onclick="gof2()">go(1)前进一页</button>
<button type="button" onclick="gof1()">go(-2)两次返回</button>
本文介绍JavaScript中history对象的使用方法,包括获取浏览器历史记录数量、实现页面前进和后退功能。通过具体示例代码,展示了如何利用history.back()、history.forward()及history.go()方法进行页面导航。
56

被折叠的 条评论
为什么被折叠?



