現在のシステムがアンドロイドかiosかを判断する

588 ワード

var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios  
if (isAndroid) {
  console.log("Andriod");
  window.location.href = 'cos1://open?type=10000&url=' + encodeURIComponent(window.location.href) //     app
}
if (isIOS) {
  console.log("iOS");
  window.location.href = 'oushangcos1://openoscar?type=10000&url=' + encodeURIComponent(window.location.href)
}