其他分享
首页 > 其他分享> > BOM_Window_属性和BOM_Location

BOM_Window_属性和BOM_Location

作者:互联网

BOM_Window_属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        //获取history
        var h1 = window.history;
        var h2 = history;

        alert(h1);
        alert(h2);

        var openBtn = window.document.getElementById("openBtn");

        alert(openBtn);

        // document.getElementById("");
    </script>
</head>
<body>


</body>
</html>

BOM_Location:地址栏对象

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>

</head>
<body>
    <input value="刷新" type="button" id="btn">
    <input value="去百度" type="button" id="goBaiDu">


    <script>
        //reload方法,定义一个按钮,点击按钮,刷新当前页面
        //获取按钮
        var btn = document.getElementById("btn");
        //绑定单机事件
        btn.onclick = function () {
            //刷新页面
            location.reload();
        };

        //获取href
        var href = location.href;
        // alert(href);
        //点击按钮去访问百度首页页面
        var goBaiDu = document.getElementById("goBaiDu");
        //绑定单机事件
        goBaiDu.onclick = function () {
            //跳转百度页面
            location.href = "https://www.baidu.com";
        };

    </script>
</body>
</html>

标签:Location,window,Window,href,location,var,BOM
来源: https://www.cnblogs.com/ailhy/p/16553956.html