BOM

 一、函数声明
 function add(a, b) {
            return a + b;
        }
        var sum = add(1 , 3);
        alert(sum);
          function add(){
              return arguments[0]+arguments[1];
          }
          alert(add(2,3));
   // 局部    内部定义的,外部可以访问。外部定义的,内部可以访问。
       function add(){
           var a=0;
           function test(){
               alert(a);
           }
           test();
       }
    add();
       //预解析    作用域 读var a和function
            var a=1;
            function add(){
                alert(a);//不加var a=2;结果为1(作用链往上找),否则为undefined
//                var a=2;
                alert (a);//加var a=2;结果为2
            }
            add();
   // 回调函数  fun是引用
        function math(a,b,fun){
            return fun(a,b);
        }
         alert(math(2,3,add));
        function add(a,b){
            return a+b;
        }
        function jianfa(a,b){
            return a-b;
        }
         //匿名函数
    alert((function(a,b){ return a+b; })(2,3));//结果为5
     var a=function(){
         alert(0);
     }
    var b=a;
    b();
 //递归 5的阶乘
    function test(sum){
        if(sum==1){
            return sum;
          }
        else{
            return sum*test(--sum);
        }

    }
    alert (test(5));
二、BOM
1.操作窗口属性
IE CHORM:
         window.screenleft浏览器距屏幕左侧距离
         window.screentop浏览器距屏幕顶部距离
IE FOX:
         window.screenX浏览器距屏幕左侧距离
         window.screenY浏览器距屏幕顶部距离
浏览器的左侧和顶部的边距
           alert((window.screenLeft||window.screenX) + " " + (window.screenTop||window.screenY));
2.浏览器尺寸
IE CHORM(不准):
                window.innerWidth :获取浏览器的宽度,不计算标题栏
                window.innerHeight:获取浏览器的高度,不计算标题栏
IE :            
                 document.documentElement.clientWidth 
                 document.documentElement.clientHeight
 //浏览器的尺寸
            //FF,CHROM
//            alert(window.innerWidth + " " + window.innerHeight);
            //IE
//            alert(document.documentElement.clientWidth + " " + do   cument.documentElement.clientHeight);
3.窗口移动和改变尺寸的方法(IE有效)
    window.moveBy(x,y)相对于当前位置
    window.moveTo(x,y)相对于屏幕
    window.resizeBy(x, y)相对于自身水平垂直展开
     window.resizeTo(x, y);固定尺寸
4.滚动条控制
                scrollBy(x,y)相对于本身的位置,x 水平方向, y 垂直方向
                scrollTo(x,y)相对于原点进行偏移
5.打开新窗口

window.open(URL,name,features,replace)
features:  
     height窗口文档显示区的高度。以像素计。,
    left窗口的 x 坐标。以像素计。
    width窗口的文档显示区的宽度.
    top    窗口的 y 坐标。
    scrollbars=yes|no|1|0    是否显示滚动条。默认是 yes。
    titlebar=yes|no|1|0    是否显示标题栏。默认是 yes。
    toolbar=yes|no|1|0    是否显示浏览器的工具栏。默认是 yes。
    location=yes|no|1|0    是否显示地址字段。默认是 yes。
function openwin()  
{  
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no ,scrollbars="+scroll+",menubar=no");  
6.setInterval(function(){
  code要调用的函数或要执行的代码串
}, times);
  times:周期性执行或调用 code 之间的时间间隔,以毫秒计。
返回值
一个可以传递给 Window.clearInterval() 从而取消对 code 的周期性执行的值。
时间倒数例子:
   <script>
            window.onload=function(){
                var txt=document.getElementById("txt");
                var i=5;
                var times=setInterval(function(){
                    i--;
                    txt.innerHTML=i;
                },1000);
                setTimeout(function(){
                    window.clearInterval(times);
                    window.open("./open.html", "_blank", "", "width=300px,height=300px,left=500px,top=300px")

                },6000);
            }
    </script>
<body>
    <span>倒计时</span> <span id="txt"></span>
</body>

   三、 history 访问历史页面 length/go()/forward()/back()

          属性:
               length 表已防问的页面个数
          示例:
               alert(window.history.length);
          方法:
             go()方法 注:当值为正数,向前进相应的数,当为0,即刷新
             forward()方法 表返回
             back()方法 表返回

         示例:
          window.onload=function(){
            var button1 = document.getElementById("button1");
            var button2 = document.getElementById("button2");
            var button3 = document.getElementById("button3");
            button1.onclick=function(){
               //访问历史页面 history 的go()方法 注:当值为正数,向前进相应的数,当为0,即刷新
                window.history.go(1);
            };
            button2.onclick=function(){
                //访问历史页面 history 的forward()方法 表返回

                window.history.forward();
            };
            button3.onclick=function(){
                //访问历史页面 history 的back()方法 表返回
                window.history.back();
            };
 
     四、 location href/search/assign()/replace()/reload()

            属性:
                
            href属性 (设置/返回一个完整的URL) 

               示例: 
            //location 的href属性(返回一个完整的URL)
            alert(window.location.href);
            alert(1);
            //location 的href属性(设置一个完整的URL)
            window.location.href="dom2.html";

           search属性 (获取URL后面的查询数据)  

               示例:  
              //location 的search属性(获取URL后面的查询数据)
             alert(window.location.search);

             方法: assign方法:页面跳转

                location 的assign()方法:页面跳转 
            window.location.assign("dom2.html");

                location 的replace()方法:页面跳转(无历史记录)


                location 的reload()方法:页面刷新
            示例: 
            var button = document.getElementById("button");
            button.onclick=function(){
                window.location.reload();
            }
          
五、screen:客户端显示屏幕信息 availHeight/availWidth/height/windth

          screen 的 availHeight属性:返回显示屏幕的高度(除任务栏)
            alert(window.screen.availHeight);

            screen 的 availWidth属性:返回显示屏幕的宽度
            alert(window.screen.availWidth);

          screen 的 Height属性:包含任务栏的高度
            alert(window.screen.availHeight);

            screen 的 Width属性:包含任务栏的宽度
            alert(window.screen.availWidth);

原文地址:https://www.cnblogs.com/alicezq/p/4783829.html