- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我想在 Chrome 中使用 Js 中的 API 屏幕。
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 -> 使用 Javascript,我们无法使用导航器锁定方向。
最佳答案
这是因为 lockOrientation
仍然是前缀。请参阅 this 中的 [2] 脚注MDN 文章。此外,在 Chrome 中,它位于 orientation.lock
下。请参阅 MDN 文章中的 [1] 脚注。
locOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation || screen.orientation.lock;
locOrientation('landscape');
请注意,并非所有浏览器都具有此功能。使用前请检查locOrientation
是否设置。
编辑将较新的 orientation.lock
添加到示例中。
关于javascript - screen.lockOrientation 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42956350/
我想在 Chrome 中使用 Js 中的 API 屏幕。 if ( navigator.userAgent.match( /(android|iphone)/gi ) ) { if
我正在使用 cordova,我正在尝试将屏幕方向锁定为 Android 的横向。我正在使用插件屏幕方向插件: https://www.npmjs.com/package/cordova-plugin-
我有以下代码: var lockOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOr
我是一名优秀的程序员,十分优秀!