Top

[Javascript] 화면의 가로 세로 길이 구하기. | Web-Programing
김경훈 (admin) | Editor | 2012/03/14 09:51:34 | 조회:5206

브라우저의 화면 가로 세로 길이 구하는 소스.


  1. <script language="JavaScript"> 
  2. function fnGetClientWidth(){    // 화면 가로 길이 구하기
  3.     var intClientWidth;
  4.     if (self.innerWidth){    // IE 외 모든 브라우저            
  5.         intClientWidth = self.innerWidth;
  6.     }else if (document.documentElement && document.documentElement.clientWidth){    // IE 6 Strict
  7.         intClientWidth = document.documentElement.clientWidth;
  8.     }else if (document.body){        // IE
  9.         intClientWidth = document.body.clientWidth;
  10.     }
  11.     return intClientWidth;
  12. }
  13. function fnGetClientHeight(){    // 화면 세로 길이 구하기
  14.     var intClientHeight;
  15.     if (self.innerHeight){
  16.         intClientHeight = self.innerHeight;
  17.     }else if (document.documentElement && document.documentElement.clientHeight){
  18.         intClientHeight = document.documentElement.clientHeight;
  19.     }else if (document.body){
  20.         intClientHeight = document.body.clientHeight;
  21.         return intClientHeight;
  22.     }
  23. }
  24. </script>



위소스로 화면의 가로 세로 길이를 구할 수 있다. 물론 익스, 파폭, 크롬에서 잘 돌아간다.


나는 위 소스를 아래처럼 적용해봤다.


  1. <script language="JavaScript"> 
  2. window.onresize = function(){ 
  3.     if (fnGetClientWidth() < 500 )
  4.     {
  5.         mobile_version()
  6.     }
  7. </script>




- 작성자 WHITESAL

공유하기
공유하기
0
0
0


댓글을 불러오는 중입니다.
▲ 이전글 [HTML] ime-mode 사용방법 김경훈 (admin) 2012-03-14 13:39:44
▼ 다음글 [Web] 웹 포토샵 김경훈 (admin) 2012-02-21 11:38:29