2017-03-22 2 views
0

Chrome에서 Js의 API 화면을 사용하고 싶습니다.screen.lockOrientation이 함수가 아닙니다.

if (navigator.userAgent.match(/(android|iphone)/gi)) { 
     if ('orientation' in screen) { 
      //console.log('// API supported, yeah!'); 
      //console.log('new orientation is ', screen.orientation); 
      screen.lockOrientation('landscape'); 
     } else { 
      console.log('// API not supported '); 
     } 
    } else { 
     //alert('none'); 
    } 

내 오류 JS : 잡힌 형식 오류 : screen.lockOrientation 함수

if (navigator.userAgent.match(/(android|iphone)/gi)) { 
    if ('orientation' in screen) { 
     let locOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation; 
     locOrientation('landscape'); 
     console.log('// API supported, yeah!' , locOrientation); 
     console.log('new orientation is ', screen.orientation); 
     //screen.lockOrientation('landscape'); 
    } else { 
     console.log('// API not supported '); 
    } 
} else { 
    //alert('none'); 
} 

내 오류 JS

/* 다른 */

되지는 : locOrientation 함수

아니다

업데이트 : 20/04/2017 -> 자바 스크립트를 사용하면 탐색기에서 방향을 고정 할 수 없습니다.

+0

은 일반 페이지 또는 앱의 경우입니까? – dandavis

+0

간단한 웹 페이지, 내 설정 : (webpack, vuejs) – Seb

+0

페이지가 아닙니다 ... – dandavis

답변

0

lockOrientation에 계속 접두어가 붙어 있기 때문입니다. this MDN 기사의 [2] 각주 참조. 또한 크롬에서는 orientation.lock입니다. MDN 기사의 [1] 각주를보십시오.

locOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation || screen.orientation.lock; 
locOrientation('landscape'); 

모든 브라우저에이 기능이있는 것은 아닙니다. 사용하기 전에 locOrientation이 설정되어 있는지 확인하십시오.

편집 : 더 새로운 orientation.lock을 예제에 추가하십시오.

+0

내 게시물을 업데이트했습니다. 내 게시물을 업데이트합니다. – Seb

+0

아, Chrome에는 orientation.lock이 있습니다! – JosiahDaniels

+0

방향을 고정하려면 탐색기를 강제로 누르는 것이 좋습니다. – Seb

관련 문제