天天看点

简单解析BOM中History对象

简单解析BOM中History对象

History 对象包含用户(在浏览器窗口中)访问过的 URL。

<button>back()</button>
    <button>forward()</button>
    <button>go()</button>
           
console.log(history);
    var aBtns=document.getElementsByTagName("button");
    // 属性
    // length  返回历史记录/列表中的网址数
    console.log(history.length);

    // 方法
    // back()	加载 history 列表中的前一个 URL   后退
    aBtns[0].onclick=function(){
        history.back();
    }
    // forward()	加载 history 列表中的下一个 URL  前进
    aBtns[1].onclick=function(){
        history.forward();
    }
    // go()	加载 history 列表中的某个具体页面  1  -1
    aBtns[2].onclick=function(){
        history.go(1);
    }
           

视频讲解链接:

https://www.bilibili.com/video/BV1aZ4y1W7SL/

继续阅读