js 怎么判断 Line 和 facebook 啊

2019-11-25 15:34:59 +08:00
 maruize321

如题,查了半天查不到

2330 次点击
所在节点    程序员
1 条回复
cheeto
2019-11-25 16:24:01 +08:00
你指的是在 line 或 FB 中打开么。。。
用 UA
```
var versions = function (){
var u = navigator.userAgent, app = navigator.appVersion;
var ua = navigator.userAgent.toLowerCase();

return { //偵測移動端瀏覽器版本信息
trident: u.indexOf('Trident') > -1, //IE 核心
presto: u.indexOf('Presto') > -1, //opera 核心
webKit: u.indexOf('AppleWebKit') > -1, //Apple, google 核心
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox 核心
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //行動裝置
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android 或 uc 瀏覽器
iPhone: u.indexOf('iPhone') > -1, //是否為 iPhone 或者 QQHD 瀏覽器
iPad: u.indexOf('iPad') > -1, //是否 iPad
webApp: u.indexOf('Safari') == -1, //是否 web 应该程序,没有头部与底部
iosv: u.substr(u.indexOf('iPhone OS') + 9, 3),//ios 版本
weixin: ua.match(/MicroMessenger/i) == "micromessenger",//微信瀏覽器
fbapp: u.indexOf('FBAV') > -1,//Facebook App 內瀏覽器
line: u.indexOf('Line') > -1//Line 內瀏覽器
};
}();

// redir to mobile version
if( versions.mobile ){
location.href = 'https://' + location.hostname + '/mobile.html';
}

// inside of weixin app
if( versions.weixin ){

}else{

}
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/622932

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX