高程三 BOM 读书笔记

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page</title>
</head>
<body>
    <button id="btn">Click to Change</button>
    <script>
        //window对象既是通过js访问浏览器窗口的一个接口,又是ECMAscript规定的global对象
        //尝试访问未声明的变量会抛出错误,而通过查询window对象则可以知道某个未声明的变量是否存在
        // var newV = oldV;//error
        var newV = window.oldV;//这是一次属性查询
        var btn = document.querySelector("#btn");
        // var url = window.open("https://www.4399.com","_self","height=500,width=500,resizable=yes");这里的resizable不是指resize
        // var url = window.open("","","height=500,width=500,resizable=yes");
        function resize(){
            url.resizeTo(500,500);//被禁用了?
            url.resizeBy(100,100);
            console.log(window.outerHeight);
            console.log(window.innerHeight);
            url.close();
            // window.open("https://www.4399.com");
        }
        // btn.addEventListener("click",resize,false);
        //系统对话框+confirm
        // if(confirm("确认?")){
        //     alert("已确认!");
        // }

        //location对象 提供了与当前窗口中加载的文档有关的信息,既是window对象的属性也是document对象的属性
        //利用location对象的属性创建一个解析查询字符串并返回所有参数
        function getQuery(){
            var queryStr = (location.search.length > 0) ? location.search.substring(1) : "";
            //返回查询字符串,并去掉问号
            var args = [];
            //建立一个字符串保存数据
            items = queryStr.length > 0 ? queryStr.split("&") : [];
            //spilt方法将字符串中&两边的部分分开
            item = null;//而不是 = "";
            name = null;
            value = null;
            for(i = 0;i<items.length;i++){
                item = item[i].split("=");
                anme = decodeURIComponent(item[0]);
                value = decodeURIComponent(item[1]);

                if(name.length){
                    args[name] = value;
                }
            }
            return args;//以后在自己写的程序中也要注意这个了
        }
        //location.assign()方法,立即打开传入的url并且在浏览器的历史纪录中生成一条记录
        //等于location.href  window.location

        //通过hash  search   hostname   patname   port属性设置为新值改变url
        //replace()方法,不会在历史纪录中生成新纪录,并且后退按钮会被禁用

        //reload()重新加载(可能从浏览器本地缓存)
        //reload(true),从服务器端重新加载

        //history对象
        history.go(-1);//history.back()
        history.go(1);//history.forward()
    </script>
</body>
</html>

 

posted @ 2019-03-11 19:04  林不渡  阅读(169)  评论(0编辑  收藏  举报