Reputation: 5238
This question is quite simple, but I want to ask it anyway.
This code tell us that user's browser is a famous Opera Mini
var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
So I can use it in this way:
if (navigator.userAgent.indexOf('Opera Mini') > -1)
alert('hey! your browser is buggy');
This is if Opera Mini, then
conditional.
How do I make a right short conditional for if not Opera mini, then
?
I'm not sure how should I play with -1
integer.
Upvotes: 2
Views: 3207
Reputation: 51
https://dev.opera.com/articles/opera-mini-and-javascript/
var isOperaMini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]"
Upvotes: 0
Reputation: 5257
From the Opera doc:
Detecting Opera Mini: 2 approaches: You can:
Examine the user agent string
Check for the presence of the operamini object
i.e. If not Opera Mini is:
if (!window.operamini){}
Short, easy and reliable. Unlike the spoof-able user-agent.
Upvotes: 3
Reputation: 193271
Another options (maybe less readable) using ~
operator:
if (~navigator.userAgent.indexOf('Opera Mini')) {
// opera mini
}
if (!~navigator.userAgent.indexOf('Opera Mini')) {
// not opera mini
}
However it's probably better for you to compare with -1
, until you are familiar with syntax.
Upvotes: 0
Reputation: 393
You can simply change it to
if (navigator.userAgent.indexOf('Opera Mini') == -1)
That will return true if it does NOT find 'Opera Mini' in the user agent string
Upvotes: 3