How to hide layout on android stock browser in AngularJS?

I have a released Beta Version of a Web-App which is written in AngularJS and uses Angular-Material. Unfortunately the layout is completely unusable and messed up on Android's Stock Browser (not chrome). As this will take some while to fix, I am trying to display a

"Sorry the Beta-Webapp is not ready for this browser yet, please use Chrome"

message.

Is there a simple way to do detect the Android Stock Browser and hide the usual layout with an ng-if and a controller method?

Answers


tl;dr

var isStockAndroid = /^Mozilla\/\d+\.\d+\s\(Linux;\sU;/.test(window.navigator.userAgent);

In Chrome Dev Tools, you can mimic the Android browser to determine the userAgent string (available via window.navigator.userAgent). You can then determine differences between this user agent string and one for the mobile Chrome browser. This will allow you to detect if the current user is on the Android browser and you could redirect to a special view in this case.

Here are a few examples of user agent strings I was able to produce with Chrome Dev Tools:

Chrome: "Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.76 Safari/537.36"

Android Browser: "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"

In all of the tests I did, it appeared that U; always appeared after "Mozilla/5.0 (Linux; when the user agent was the Android browser.

Assuming that is always true (no guarantees, but this site seems to confirm that), you could use the following code to determine if the current browser was stock Android:

var isStockAndroid = /^Mozilla\/\d+\.\d+\s\(Linux;\sU;/.test(window.navigator.userAgent);

Need Your Help

multilanguage database driven website with laravel4

php laravel laravel-4

im messing around with laravel to do a multilanguage website.

How to store the letter of a string

c# string storage

How would I store the letter in a string that has been removed from a word?