본문 바로가기
JavaScript

[JavaScript] window with, height cross Browser

by SSaMKJ 2013. 3. 25.

Window의 height, width를 가지고 올 때 Browser에 따라 다른 문법이 발생한다.


모든 브라우져에서 Window width, height을 가지고 올 수 있도록 한 코드이다.


var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') { //Chrome
         myWidth = window.innerWidth;
         myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
         myWidth = document.documentElement.clientWidth;
         myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE9
         myWidth = document.body.clientWidth;
         myHeight = document.body.clientHeight;
    }
    

'JavaScript' 카테고리의 다른 글

javascript로 브라우져 종류 알아보기.  (0) 2013.05.16
serialize form  (0) 2013.04.23
자바스크립트 선택  (0) 2013.04.17
JSON 표기법으로 클래스 생성  (0) 2013.03.25
사용자 함수 만들기 2가지 방법  (0) 2013.03.25

댓글