我目前正在使用以下代码根据this post
检测网页浏览var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
它完全适用于Fb应用,但不适用于Twitter应用。请帮忙。
答案 0 :(得分:1)
使用这个:
从this is part of visual js game engine project
下载来源
/////////////////////////////////////
// Usage
//////////////////////////////////////
var BROWSER = new DETECTBROWSER()
alert(BROWSER.NAME)
<script>
function DETECTBROWSER(){
var HREFF,HREFTXT = "unknown";
this.NAVIGATOR = navigator.userAgent;var NAV =navigator.userAgent;var gecko,navIpad,operatablet,navIphone,navFirefox,navChrome,navOpera,navSafari,navandroid,mobile,navMozilla,Macintosh,MacOS;
gecko=NAV.match(/gecko/gi);
navOpera=NAV.match(/opera/gi);
operatablet=NAV.match(/Tablet/gi);
navIpad=NAV.match(/ipad/gi);
navIphone=NAV.match(/iphone/gi);
navFirefox = NAV.match(/Firefox/gi);
navMozilla = NAV.match(/mozilla/gi);
navChrome = NAV.match(/Chrome/gi);
navSafari = NAV.match(/safari/gi);
navandroid = NAV.match(/android/gi);
mobile = NAV.match(/mobile/gi);
Macintosh = NAV.match(/Macintosh/gi);
MacOS= NAV.match(/Mac OS/gi);
window["TYPEOFANDROID"] = 0;
window["NOMOBILE"] = 0;
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
var userAgent = navigator.userAgent.toLowerCase();
if ((userAgent.search("android") > -1) && (userAgent.search("mobile") > -1))
console.log("ANDROID MOBILE")
else if ((userAgent.search("android") > -1) && !(userAgent.search("mobile") > -1))
console.log(" ANDROID TABLET ")
TYPEOFANDROID = 1;
}
else {NOMOBILE=1; }
// FIREFOX za android
if(navFirefox && navandroid && TYPEOFANDROID == 0){HREFF = "#"; HREFTXT = "mobile_firefox_android"; }
// FIREFOX za android T
if(navFirefox && navandroid && TYPEOFANDROID == 1){HREFF = "#"; HREFTXT = "mobile_firefox_android_tablet"; }
// OPERA ZA ANDROID
if(navOpera && navandroid){HREFF = "#"; HREFTXT = "opera_mobile_android"; }// provera
// OPERA ZA ANDROID TABLET
if(navOpera && navandroid && operatablet){HREFF = "#"; HREFTXT = "opera_mobile_android_tablet"; }// provera
// safari mobile za IPHONE - i safari mobile za IPAD i CHROME za IPAD
if(navSafari){
var Iphonesafari = NAV.match(/iphone/gi);
if (Iphonesafari){HREFF = "#"; HREFTXT = "safari_mobile_iphone"; }
else if (navIpad){ HREFF = "#"; HREFTXT = "mobile_safari_chrome_ipad"; }
else if (navandroid){ HREFF = "#"; HREFTXT = "android_native"; }
if( Macintosh && MacOS) { HREFTXT = "safari_desktop";}
}
// TEST CHROME
if(navChrome && navSafari && navMozilla && TYPEOFANDROID == 1){HREFF = "#"; HREFTXT = "mobile_chrome_android_tablet"; }
if(navChrome && navSafari && navMozilla && TYPEOFANDROID == 0){HREFF = "#"; HREFTXT = "mobile_chrome_android"; }
if(navChrome && TYPEOFANDROID == 0 ){HREFF = "#"; HREFTXT = "chrome_browser"; }
if(navMozilla && NOMOBILE==1 && gecko && navFirefox){HREFF = "#"; HREFTXT = "firefox_desktop"; }
if( navOpera && TYPEOFANDROID == 0 && !mobile){HREFF = "#"; HREFTXT = "opera_desktop"; }
this.NAME = HREFTXT;
this.NOMOBILE = NOMOBILE;
}
//###############################################//###############################################
//###############################################//###############################################
</script>