H5判断环境 Android和IOS

H5判断环境 android和ios

  • 使用
console.log('环境判断',detect())
  • 代码
detect(){
	let equipmentType = "";
	let agent = navigator.userAgent.toLowerCase();
	let android = agent.indexOf("android");
	let iphone = agent.indexOf("iphone");
	let ipad = agent.indexOf("ipad");
	if(android != -1){
		equipmentType = "android";
	}
	if(iphone != -1 || ipad != -1){
		equipmentType = "ios";
	}
	return equipmentType;
}
posted @ 2021-04-20 11:52  小泽沐优声  阅读(265)  评论(0编辑  收藏  举报