h5页面ios系统和安卓系统兼容存在的问题

1,353 阅读1分钟

一、ios存在的问题

1、日期问题

对于yyyy-mm-dd hh:mm:ss 这种格式在ios系统不识别 时间格式化的时候,在浏览器端处理好好的,到了手机端,就变成NAN,或者null,这种情况,是ios系统不能转化这种类型的时间。

let date = new Date('2019-02-28 18:33:24');    // null

解决方案是,转成 yyyy/mm/dd hh:mm:ss 这种格式就可以了 replace(/-/g, "/")

2、复制问题

function copy(txt) {
  const input = document.createElement('input');
	input.setAttribute('readonly', 'readonly');  //input设置只读,ios就不会拉起键盘
	input.setAttribute('value', txt);
	document.body.appendChild(input);
	if (input.select()) {
		input.select();
	} else {
		input.setSelectionRange(0, 9999); //选中内容
	}
	if (document.execCommand('copy')) {
    document.execCommand('copy');
	}
	input.style.display = 'none';
	document.body.removeChild(input);
}

3、H5页面适配 iPhoneX全面屏手机

20201108151232146.png

20201108151353106.png

padding-bottom: contain(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);

二、安卓系统存在的问题

1、底部bottom固定定位,安卓弹起键盘导致页面变形如何解决?(底部为固定定位,安卓端在页面中文本框input获取焦点时,手机自带的键盘会被唤起并且弹出来被键盘顶上去,漂浮于键盘上方)

一、在android中软键盘弹起或收起时,会改变window的高度,因此监听window的onresize事件,在键盘弹起的时候,

//获取原窗口的高度
var originalHeight=document.documentElement.clientHeight ||document.body.clientHeight;
window.onresize=function(){
    //键盘弹起与隐藏都会引起窗口的高度发生变化
       var resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
        if(resizeHeight-0<originalHeight-0){
         //当软键盘弹起,在此处操作
         //将固定定位变为相对定位
         setTimeout(function() {  //有的可以用这种方法
            e.target.scrollIntoView(true)
            e.target.scrollViewIfNeeded()
        }, 200)
         }else{
         //当软键盘收起,在此处操作
         //将相对定位变为固定定位
         }
}

参考:总结几个移动端H5软键盘的大坑及其解决方案