0

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.

enter image description here

Hyunjin Lee
  • 113
  • 1
  • 15
  • Possible duplicate of [Opera Mini Browser Detection Using Javascript](https://stackoverflow.com/questions/36653217/opera-mini-browser-detection-using-javascript) – Hyyan Abo Fakher Jul 24 '18 at 10:36
  • @HyyanAboFakher I edited Question. – Hyunjin Lee Jul 24 '18 at 10:47
  • 1
    Please check if it can help: https://github.com/lancedikson/bowser/issues/158 – NullPointer Jul 24 '18 at 11:18
  • 1
    Which version of Opera Mini? ... and does it use the old _preston_ engine or the new _webkit_? – Ason Jul 24 '18 at 11:19
  • @LGSon 16.0.12 I downloaded today! – Hyunjin Lee Jul 24 '18 at 11:21
  • And what does this evaluate to: `var isOpera = !!window.opera;` – Ason Jul 24 '18 at 11:22
  • @LGSon isOpera is false.... – Hyunjin Lee Jul 24 '18 at 11:25
  • And what about this one `var isOpera = ("-o-prefocus" in document.body.style)` .....or this one `var isOpera = ("-o-prefocus" in document.createElement("p").style)` – Ason Jul 24 '18 at 11:33
  • 1
    More importantly, for what do you need to detect if it is Opera? ...also, Opera 16 runs with Webkit engine, hence the different user agent, ...and the most likely reason they changed, is to get by many web servers that will block Opera mini as not being CSS3/HTML5 compliant (Microsoft did a similar trick with Windows phone). ...and all this simply shows why to **not** spoof user agent but rather detect features. – Ason Jul 24 '18 at 11:41

1 Answers1

1

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

Ason
  • 79,264
  • 11
  • 79
  • 127