2015-05-04 66 views
2

我有一個奇怪的問題。我有一個LG g700平板電腦,我想設置方向鎖定。平板電腦錯誤的屏幕方向

window.screen.orientation.lock("landscape") 

但是,當我在我的平板電腦做同樣的代碼,這是行不通的,它給出了一個錯誤,如:

Uncaught (in promise) DOMException: The page needs to be fullscreen in order to call lockOrientation(). {message: "The page needs to be fullscreen in order to call lockOrientation().", name: "SecurityError", code: 18, INDEX_SIZE_ERR: 1, DOMSTRING_SIZE_ERR: 2…}code: 18message: "The page needs to be fullscreen in order to call lockOrientation()."name: "SecurityError"__proto__: DOMException 
但是當我測試它在我的Nexus 5將其與下面的代碼效果很好

有沒有解決方案呢?

回答

1

這隻能在全屏模式下完成。所以我建議你在調用screen.orientation之前增加一個超時,以確保全屏處於活動狀態並準備就緒。

if (document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen) { 
    setTimeout(function(){ 
     window.screen.orientation.lock("landscape"); 
    } , 200); 
} 
相關問題