Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if web page is loaded within native Facebook app on iOS / Android

I have a web app using the Facebook javascript SDK. I want to detect if this web app is running within the native Facebook app on iOS or Android. The reason is because if not running within a proper browser I want to open certain links in a floating iframe instead of a new web page/tab.

How can I easily detect if running on mobile within the native Facebook app. I am aware of the answer that suggests using FB.UA but that answer is 3 years old and that API is not documented anymore.

OR

Is it possible specify an HREF to launch a URL in the native browser on a mobile device? Then my links could launch a browser and my web app keeps running within the Facebook native app.

like image 874
techsMex Avatar asked Apr 15 '15 16:04

techsMex


People also ask

Does Facebook use WebView?

Our in-app browser for Facebook on Android has historically relied on an Android System WebView based on Chromium, the open source project that powers many browsers on Android and other operating systems.

Can a website check if an app is installed?

Your website can check if your PWA is installed, even if the page is outside the scope of your PWA. For example, a landing page served from /landing/ can check if the PWA served from /pwa/ is installed, or if your landing page is served from www.example.com and your PWA is served from app.example.com .

How do you check whether the app is installed in Android device or not using Javascript?

The closest that you can do is in the application, have an activity that has an <intent-filter> for some URL structure, and have a link in the mobile Web site to a matching URL. If the user clicks the link and the app is installed, the activity will be a chooser option for the user.


1 Answers

This works fine for me in JavaScript:

if (navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/FBAV/i)) {
    //iOS Facebook App Browser detected
}
like image 126
andyrandy Avatar answered Oct 12 '22 10:10

andyrandy