在 JS 中,HISTORY 对象代表窗口的浏览历史记录。
// 点击原始网页中的按钮跳转到新网页
document.getElementById("btn1").onclick = function(){
window.location.href = "http://www.baidu.com"; // 页面跳转到百度
}
// 点击新网页中的按钮,返回原始网页
document.getElementById("btn2").onclick = function(){
window.history.back();
}
// 点击原始网页的另一按钮,又回到新网页
document.getElementById("btn3").onclick = function(){
window.history.forward(); // 页面跳转到百度后返回,再点击这个按钮,通过历史记录又回到百度
}