How to detect Facebook in-app browser?

后端 未结 3 1156
南方客
南方客 2020-11-29 01:17

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.

相关标签:
3条回答
  • 2020-11-29 01:36

    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
    };
    
    0 讨论(0)
  • 2020-11-29 01:49

    You can use https://www.npmjs.com/package/detect-inapp and check if inapp.isInApp() is true

    0 讨论(0)
  • 2020-11-29 01:50

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

    You can also check for Instagram in the user agent as well: (ua.indexOf('Instagram') > -1)

    0 讨论(0)
提交回复
热议问题