Update: thanks for the answers, but I want to clarify that I am a javascript developer and not an android app developer, and I need to detect on runtime whether a website is loaded in Android's browser or loaded in a WebView of an app, only by javascript code
Original Question: How can Javascript detect on runtime whether a website is loaded in Android's browser or loaded in a WebView of an app, when I am not in charge on the application?
I believe that the user agent will be the same for both the browser and the webview so that won't tell the difference.
What you can do however is to attempt to bind javascript code to android code and call it. If it succeeds then its running in webview, or if it fails then its in browser.
For more information on how to do this see:
http://developer.android.com/guide/webapps/webview.html#BindingJavaScript
Example (Java/Javascript may not be right):
@JavascriptInterface
public void userAgentDetect() {
WebView = true;
}
Set the WebView variable to false then attempt to run the function.
Then check that WebView boolean to confirm whether its in the app or browser.
EDIT: Here is another example: Detect inside Android Browser or WebView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With