var u = navigator.userAgent
var isAnd = u.indexOf(‘Android‘) > -1 || u.indexOf(‘Adr‘) > -1//安卓
var ios = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)//ios
if(isAnd)console.log(‘安卓‘)
if(ios)console.log(‘ios‘)
原文:https://www.cnblogs.com/MrzhangRecord/p/9481079.html