Search code examples
javascriptbrowseruser-agentopera-mini

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


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


Solution

  • 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