Code to parse user agent string?
The get_browser() function has been available in PHP for quite a long a time. The PHP manual is free, can be downloaded in various formats and viewed online (with comments)
The get_browser() function has been available in PHP for quite a long a time. The PHP manual is free, can be downloaded in various formats and viewed online (with comments)
You probably have a normal site and you want to redirect to a mobile site if certain conditions are met, like the screen is very small, or the content is zoomed out to fit on a large “virtual” screen in a small physical space. So, why not check for those conditions instead of testing a … Read more
Use the native PHP $_SERVER[‘HTTP_USER_AGENT’] variable instead.
This is working for me. Object.defineProperty(navigator, ‘userAgent’, { get: function () { return ‘Mozilla/5.0 (Windows NT 6.2; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0)’; } }); It is an updated version of code4coffee’s answer as Object.prototype.__defineGetter__() is deprecated: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__
As per Chrome dev docs: “If you’re attempting to differentiate between the WebView and Chrome for Android, you should look for the presence of the Version/X.X string in the WebView user-agent string.”
Yet try a new library that is updated monthly and available in The Central Repository: http://uadetector.sourceforge.net/ It is another wrapper for user-agent-string.info, but with a much more solid and tested implementation compared to the other ones. I’m working on a stable API 1.0 which I want to release at the end of this year. After … Read more
Indeed, while option change in Settings may be a good solution for the user, as a developer you can’t rely on that. It is as weird as to ask the user to not to use dark mode cause your app doesn’t support it instead of opt-out of it using plist. As for me, the most … Read more
The webRequest API can be used to modify the User Agent header. Note: The Network tab at the Developer tools show the old headers. I’ve verified that the headers are set correctly, using netcat (nc -l 127.0.0.1 -p 6789). In the example below, the code activates on all tabs. Adjust the request filter to meet … Read more
It depends on which version of cordova-android and cordova-ios you are using. You can check the platform cordova versions by running cordova platform list If you are using 4.0 and above versions for both iOS and Android you can set them in config.xml as stated in cordova documentation here <preference name=”OverrideUserAgent” value=”Mozilla/5.0 My Browser” /> … Read more
The closest you can come with pure CSS is with feature queries. Instead of detecting the browser type/version, it allows you to check if a specific property/value combinations are supported by the browser. The following is an example of using the transform property for vertical centering. If the browser doesn’t support transform, then we don’t … Read more