Javascript 如何检测 Facebook 应用内浏览器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31569518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect Facebook in-app browser?
提问by milosz0010
Have you had any experience in Facebook in-app browser detection? What's the core difference in user agent?
你有过 Facebook 应用内浏览器检测的经验吗?用户代理的核心区别是什么?
I don't want to know if it is a only mobile/ios/chrome. I need to know whether user agent is specific from Facebook in-app browser
我不想知道它是否是唯一的移动/ios/chrome。我需要知道用户代理是否特定于Facebook 应用内浏览器
回答by Jan Swart
You can check for FBAN / FBAV in the user agent.
您可以在用户代理中检查 FBAN / FBAV。
Check this link: Facebook user agent
检查此链接: Facebook 用户代理
Sample code as @sascha suggested
@sascha 建议的示例代码
function isFacebookApp() {
var ua = navigator.userAgent || navigator.vendor || window.opera;
return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1);
}
You can also check for Instagram
in the user agent as well: (ua.indexOf('Instagram') > -1)
您还可以Instagram
在用户代理中检查:(ua.indexOf('Instagram') > -1)
回答by Javier Gutierrez Martin
this javascript works well
这个 javascript 运行良好
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
if( ios ) {
if ( !standalone && safari ) {
//browser
} else if ( standalone && !safari ) {
//standalone
} else if ( !standalone && !safari ) {
//uiwebview (Facebook in-app browser)
};
} else {
//not iOS
};