bom 의 총 결 1: window 대상

4101 단어
window 개체
window 대상 은 브 라 우 저의 인 스 턴 스 입 니 다. 이중 역할 이 있 습 니 다. 자바 script 이 브 라 우 저 창 을 방문 하 는 인터페이스 이자 ECMAScript 의 Global 대상 입 니 다.
1. window 대상 의 전역 역할 영역
            ,  ,      window     
    var age = 20;
    console.log(window.age);
    function sayAge() {
        console.log('    :'+window.age);
    }
    window.sayAge();
    1.1       window           ,      delete  
    console.log(delete(age));//        false
    window.height = 180;
    console.log(delete(window.height));//  true
    console.log(window.age);//    
    console.log(window.height);//    
    >   :ie8     delete  window      ,          

2. 창 관계 및 프레임 워 크
이 부분 은 나중에 보충 하면 자바 script 고급 프로 그래 밍 제3 판 P194 를 참고 할 수 있 습 니 다.
3. 창 위치
    var leftPos = (typeof window.screenLeft == "number")?window.screenLeft:window.screenX;
    var topPos = (typeof window.screenTop == "number")?window.screenTop:window.screenY;
    alert('    :'+leftPos + '    :'+topPos);
          ,    
    >  :window.moveTo window.moveBy             .

4. 창 크기
      //            : chrome         , IE8         
      console.log('    :'+ window.outerWidth + ' ' + window.outerHeight);
      //      :
      var pageWidth = window.innerWidth,pageHeight = window.innerHeight;
      if (typeof pageWidth != "number"){
        if (document.compatMode == "CSS1Compat"){
            pageWidth = document.documentElement.clientWidth;
            pageHeight = document.documentElement.clientHeight;
        } else {
            pageWidth = document.body.clientWidth;
            pageHeight = document.body.clientHeight;
        }
      }

5. 창 탐색 및 열기
    //    :     .    :1:    url,
    // 2.    ,       :_blank,_self,_parent,_top
    // 3.       ,
    // 4.                             
    var otherWindow = window.open('http://piaoshu.org','otherWindow','height=400,width=400,left=100,top=100');
    console.log(otherWindow.opener);
    console.log(otherWindow.opener === window);//  true
    otherWindow.resizeTo(600,600);
    console.log(otherWindow.closed);//  false
    otherWindow.close();
    console.log(otherWindow.closed);//  true
    //          ,   
    window.open('http://baidu.com');
    //                  ,        
    //             
    var blocked = false;
    try {
        var wroxWin = window.open("http://www.wrox.com", "_blank");
        if (wroxWin == null){
            blocked = true;
        }
    } catch (ex){
        blocked = true;
    }
    if (blocked){
        alert('         ,   ');
    }

6. 시간 초과 호출 과 간헐 호출
    //      :               ,  js        ,               
    //      ,js       ,      ,       .
    var timeId = setTimeout(function () {
        console.log('    ');
    },1000);
    clearTimeout(timeId);//             
    //      :              ,          ,      
    var count = 60, interval = null;
    var logFun = function () {
        console.log('        ');
        console.log(count);
        count -= 1;
        if(count <= 50){
            clearInterval(interval);
        }
    };
    interval = setInterval(logFun,1000);
    //               ,,  ,                        (                  ),                :
    var num = 0,max = 10;
    var numFun = function () {
        console.log(num);
        num ++;
        //             ,        
        if(num <= max){
            setTimeout(numFun,1000);
        }
    };
    setTimeout(numFun,1000);

7. 시스템 대화 상자
    //     :        ,            
    //1.alert:    
    alert('  alert  ');
    //2.confirm:   ,   true     ,    
    if(confirm('         ')){
        alert('    ');
    }else{
        alert('      ');
    }
    //3.prompt        
    var result = prompt('       ','  ');
    if(result != null){
        console.log('  ');
    }

좋은 웹페이지 즐겨찾기