How to detect Facebook in-app browser?

半世苍凉 提交于 2019-11-26 10:35:39

问题


Have you had any experience in Facebook in-app browser detection? What\'s the core difference in user agent?

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


回答1:


You can check for FBAN / FBAV in the user agent.

Check this link: Facebook user agent

Sample code as @sascha suggested

function isFacebookApp() {
    var ua = navigator.userAgent || navigator.vendor || window.opera;
    return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1);
}



回答2:


To complete worker11811's answer on using the user agent, here's a code snippet to make it work:

function isFacebookApp() {
    var ua = navigator.userAgent || navigator.vendor || window.opera;
    return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1);
}



回答3:


this javascript works well

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
};


来源:https://stackoverflow.com/questions/31569518/how-to-detect-facebook-in-app-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!