如何在设备定向时丢失输入焦点
How to lose input focus when device orientates?
我注意到,当您专注于表单元素并更改方向时,iOS设备会锁定网站的视图。
我想知道是否有办法修改已经实现的这段代码,以包括失去<input>
的功能,<select>
专注于横向或纵向方向?
这是我已有的代码:
// Fix HTML width issues on device orientation
window.document.addEventListener('orientationchange', function() {
var iOS = navigator.userAgent.match(/(iPad|iPhone|iPod)/g);
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (iOS && viewportmeta) {
if (viewportmeta.content.match(/width=device-width/)) {
viewportmeta.content = viewportmeta.content.replace(/width=[^,]+/, 'width=1');
}
viewportmeta.content = viewportmeta.content.replace(/width=[^,]+/, 'width=' + window.innerWidth);
}
// If you want to hide the address bar on orientation change, uncomment the next line
window.scrollTo(0, 0);
}, false);
任何帮助将不胜感激,谢谢
尤里卡!
window.document.addEventListener('orientationchange', function(){
if (window.orientation === 90 || window.orientation === -90){
document.activeElement.blur();
}
else if(window.orientation === 0) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
viewportmeta.content = viewportmeta.content.replace(/width=[^,]+/, 'width=' + window.innerWidth);
}
window.scrollTo(0, 0);
}, false);
相关文章:
- 在IE9中的输入字段中输入焦点最近按钮
- 那里的维基媒体代码是如何输入焦点的
- 无法通过 JavaScript 在输入焦点上触发键盘
- 输入焦点关闭键盘,需要长时间触摸
- jQuery-滚动到某个元素时自动输入焦点
- 输入:焦点只工作一次
- 输入焦点取决于更大的父元素与 jQuery
- 如何定位单个输入焦点
- 关闭输入焦点上的滑动菜单
- 输入焦点字段,然后在页面加载时添加类
- 无法使用 keyUp 更改表内的输入焦点
- 如何在设备定向时丢失输入焦点
- Phonegap Android 在输入焦点 Javascript 上显示键盘
- 在 CkEditor 中输入焦点
- 如何使用js更改平板电脑上的输入焦点
- 在输入焦点时隐藏ios设备上的键盘
- 当鼠标悬停在其他元素上时,如何删除和重新设置输入焦点
- onmousedown事件停止输入焦点
- ngTags输入焦点自动完成
- 使用jQuery验证器禁用自动输入焦点