window.navigator.userAgent中有浏览器信息
// match()是能用正则的字符串方法,返回数组或者null
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios)/i))) {
alert('ios')
}else if((navigator.userAgent.match(/(Android)/i))){
alert('android')
}else{
alert('pc')
}
// test是正则方法,返回true或者false
if(/(phone|pad|pod|iPhone|iPod|ios)/i.test(navigator.userAgent)) {
alert('ios')
}else if(/Android/i.test(navigator.userAgent)){
alert('android')
}else{
alert('pc')
}