[英]How to lose input focus when device orientates?
I've noticed that iOS devices lock the view of your website when you're focused on a form element and change orientation. 我注意到,当您专注于表单元素并更改方向时,iOS设备会锁定网站的视图。
I was wondering if there is a way to modify this code already implemented to include the functionality to lose <input>
& <select>
focus on orientation whether landscape or portrait? 我想知道是否有办法修改已经实现的代码,使其包含失去
<input>
和<select>
专注于横向(纵向还是纵向)功能的功能?
Here is the code I have already: 这是我已经拥有的代码:
// 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);
Any help would be greatly appreciated, thanks 任何帮助将不胜感激,谢谢
Eureka! 尤里卡!
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.