2013-10-22 3 views
0

웹 브라우저 (특히 Safari)에서 모바일 웹 응용 프로그램의 방향을 변경할 때 Javascript 함수를 호출하려고합니다. 경고 메시지가 표시되지 않아 내 몸 태그에 대한 onorientationchange가 실행되지 않습니다. 내가 몸의 부하에 전화를 걸면 경고가 표시됩니다. 모바일 웹 브라우저의 방향이 바뀔 때 함수를 트리거하는 방법에 대한 아이디어가 있습니까?모바일 HTML 몸체에서 Javascript 함수 호출 onorientationchange

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
     <script type="text/javascript"> 
      function updateOrientation() { 
       var displayStr = 'Orientation: '; 
       alert("orientation=" + window.orientation); 
       switch(window.orientation) { 
        case 0: 
         //do something 
         break; 

        case -90: 
         //do something 
         break; 

        case 90: 
         //do something 
         break; 

        case 180: 
         //do something 
         break; 
       } 
      } 
    </script> 
    </head> 
    <body onorientationchange="updateOrientation();"> 
    </body> 
</html> 
+0

왜 페이지 상단에 xml 태그가 있습니까? ''이면 충분합니다. :) – VDP

+0

이것은 xhtml 페이지입니다. – c12

답변

1

이 jQuery를 사용하는 방법에 대한 아이폰 시뮬레이터

<head> 
<script type="text/javascript"> 
    window.onorientationchange = function(){ 
     alert(window.orientation); 
    } 
</script> 
</head> 

<body> 
<span>sample page</span> 
</body> 

1

어떻게 작동?

$(window).on('orientationchange', function(event) { 
    alert('changed'); 
});