Why is the User-Agent of Opera mini printed strangely on iPad? - javascript

I print User-Agent string of Opera mini on iPad using JavaScript like below.
alert(navigator.userAgent);
Result is
Mozilla/5.0 (iPad; CPU OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77
I don't know how can I detect this browser that is Opera Mini.

Why is the User-Agent of Opera mini printed strangely on iPad?
Opera 16 runs with Webkit engine, hence the different user agent.
With Webkit it now support a lot of features the older version (using the Presto engine) didn't.
The reason they changed it, is most like to get by many web servers that will block the older Opera, where they often is spoofing the user agent, and when finding opera mini, block it as being outdated (and note, Microsoft did a similar trick with Windows phone)
...how can I detect this browser that is Opera Mini
Short answer, you can't
Longer answer, there are CSS features like -o-prefocus, media query hacks etc., many of them you can find here: http://browserhacks.com/
The downside with these, when that browser specific property disappears, so will your detection.
Instead, embrace the more future proof way and detect a feature, with e.g. #supports()
At this question there is some more interested reading with how-to using both CSS and script
Instead of using prefixes I want to ask site visitors to upgrade their browser

Related

How can I detect the users browser client side? [duplicate]

This question already has answers here:
How to detect Safari, Chrome, IE, Firefox and Opera browsers?
(30 answers)
Closed 6 years ago.
I know this is bad practice and feature recognition should be the way to go in terms of building the website. However that is not my use case.
I have different distributions of my browser extension and I would like to change the download button based on their current browser.
I've tried using navigator.userAgent, that has proven to be quite useless as most browsers have set all popular user agents. For example chrome has this.
navigator.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
I've seen many websites have this feature on their download buttons. How is this done properly?
EDIT: I've now learned the history of why "Mozzila/X.X" is at the start of the userAgent string. Apologies for the misunderstanding.
You can detect browsers in multiple ways.
For Chrome, apart from making a regex on the navigator.userAgent:
var isChrome = /Chrome/.test(navigator.userAgent);
You can also make a check on:
var isChrome = !!window.chrome && !!window.chrome.webstore;
I suggest you to see this answer for further details.
You should also consider using Modernizr.js for browser detection.

Internet Explorer ver 11 enterprise mode detection

Recently my team has landed in a weird situation. End of last year we migrated from IE 8 to IE 11. Our application is now designed to work in IE 11 Enterprise mode.
We need to display a javascript alert message to upgrade the Browser if the user is using IE 8. Alert message is successfully displayed to the users who use IE 8. But problem occurs when the alert message is also displayed to the users who are using IE11 in enterprise mode. I know that IE11 Enterprise mode basically emulates IE 8 behavior and that is the reason why our browser detection functionality is failing.
So I wanted to check if someone has implemented this kind of feature where they can successfully detect the IE version even if they are using IE 11 enterprise mode.
All responses are valuable. Appreciate your response !!!
As per MSDN:
As of Internet Explorer 11, the user-agent string has changed
significantly...Sites that rely on the user-agent string should be
updated to modern techniques, such as feature detection, adaptive
layout, and other modern practices.
https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
Although IE11 in EM throws
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; Tablet PC 2.0)
It is not advisable to just look for "MSIE" in the userAgent but rather try:
var isIE11 = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./)
I'm just looking into this myself. I did stumble across this recently - but couldn't get it to work reliably - however the concept of looking for a feature of IE that shouldn't normally be available is sound.
My plan now is to use IETruth to get the version number (it's very good at doing version detection for IE11) and then do something like:
var IE = IeVersion();
if(IE.TrueVersion < 9 && ('spellcheck' in document.createElement('textarea')) {
// must be running in Enterprise mode because spellcheck wasn't introduced until IE10
}
I'll let you know how I get on!
You can use document mode to check for Enterprise mode. Because in EM the document mode is set to IE 5 to IE 8. This check along with your browser check functionality should work.
How to get browser "Document Mode"

AudioBufferSourceNode - start vs noteOn

Is there any reason to use AudioBufferSourceNode.start(...) over AudioBufferSourceNode.noteOn(...)?
Yes. start() will work in Mozilla's nascent Web Audio implementation, and will work in Safari in the future. noteOn() won't.
As of today NoteOn does not work in Google Chrome, so you must use start(). (2014-07-24)
(This should be a comment but I don't have the rep.)
My company's developers confirmed that noteOn() began to fail in browsers that use recent versions of WebKit, but that to start() is a reliable alternate. Sorry, I don't know the specific version of WebKit, but affected browsers include:
All native browsers for iOS 10.3 (and above). This is due to Apple's requirement to use WebKit on that platform, including Safari, Chrome, Firefox, and Opera. As an example of a non-native "browser", Puffin is really a remote-access portal to a LINUX window, so it is unaffected. (Apple recently pulled Puffin Academy from the store, but it may be a misunderstanding of the method used, or may be a tightening of their requirements.)
Safari 10.1 (and above) for Mac OS X 10.10 through macOS 10.12 (and above).

Directing clients to the correct page to download IE for their OS version

Just build a site and we're having issues with IE7 users. It had nothing to do with my programming, but a site we have to redirect the customers to that does not handle IE7. Problem is that the client base is not overly tech savvy and telling them to update their version of IE requires they understand what version of Windows they're using (XP or Vista) and also whether their version is 32-bit or 64-bit which I'm sure will really scare the users off.
The issue pretty much boils down to needing to find a way to detect what version of Windows they're using (XP or Vista ... Windows 7 won't run IE7) and then find a way to alert them as to whether they're using 32-bit or 64-bit and direct them accordingly.
Not sure if anyone else has come across this problem and curious how they've handled it.
As you want to find the useragent using javascript, use this
var user_agent = navigator.userAgent
The output to the above command on my machine is:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
The UserAgent string in the http header can often be used to determine their OS, Browser, and their architecture (32 vs 64).

Strange User Agent With Google Chrome

I was working with some javascript and found a strange user agent with my Google Chrome.
I have Google Chrome 7.0.517.41 beta installed on my Ubuntu Laptop.
Now AFAIK my user agent should be something close to Chrome/7.0.517.41
but it is showing me:
Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7
Why is this happening.. I have disabled all the installed extensions but it is still the same..
The UA string tells the long and tragic history of (in)compatibility attempts. See e.g. this for a brief history of the UA. It should also make clear that UA sniffing is useless, as every modern browser pretends to be many other browsers. That is also the case you see here:
Mozilla - the most ancient artefact, dating from the early 1990s
X11 - the graphical interface used
Linux i686 - OS and processor type
en_US - your locale (English, United States)
AppleWebKit/534.7 - the actual rendering engine
(KHTML, like Gecko) - another artifact of browser sniffing: "Gecko" is the FF rendering engine, KHTML is an old rendering engine, predecessor of WebKit (was used by Konqueror browser, then forked by Apple to form WebKit)
Chrome/7.0.517.41 - the actual browser version
Safari/537 - yet another artifact against scripts sniffing for "Safari" (which uses the same engine)
In short: some broken sites assumed that "only allowing people with Mozilla/Firefox/Webkit/whatever" is a sensible policy; in turn, browsers started lying about their origins to get around these artificial barriers. The UA strings are the result: bloatware, full of useless garbage.
Basically, Mozilla stands for "Mozilla compatible" while "KHTML, like Gecko" describes the rendering engine.
Essentially, Chrome's user agent string is saying "I'm compatible with Mozilla and my rendering engine is like Gecko" as a way of describing itself to developers.
Most (if not every) browser will identify itself as Mozilla-compatible as a kind of legacy thing, regardless of affiliation with the Mozilla foundation. Yes, even Internet Explorer.
More info on strings in general at: Mozilla's developer center.
Also, if you're developing based on user agent strings, don't. You'll only find yourself in a world of hurt: browsers get upgraded to implement features and your user agent sniff might still exclude them, user agent strings can be spoofed, and good old Opera likes to report itself as Internet Explorer in older versions.
Instead, use feature detection to determine if a feature you're trying to use exists for a given browser and then use it or don't.
There are historical reasons for browsers "lying" about themselfs. The main reason for this was user agent sniffing. Opera is the only browser which identifies itself as Opera, all other browsers use Mozilla/5.0 or the older ones Mozilla/4.0.
The only thing you should know about this is: User agent strings cannot be trusted, feautre detection is recommended instead.
User agent strings are like that, as mentioned.
You haven't said that explictly, but if you are planning to use useragent string to detect the user's browser, please use some good code to do that (i.e. don't code it yourself in a hurry, you'll not get it right).
Here is a nice one that I've used a couple times before: Browser detect.
After trying everything I have finally used : http://www.useragentstring.com/
You can use the above website to get the formatted user agent and OS.
They have api which you can use directly...
hope it helps..!!!

Categories

Resources