Reversing Simple Javascript User Agent Logic
Can someone help me reverse this logic?
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {}
I would like the stat开发者_高级运维ement to read as follows: If user agent is NOT iPhone or NOT iPod
Right now I'm just leaving the first IF blank and using an ELSE, but I know there has to be a better solution.
Is there an opposite to .match?
Thanks!
Just for giggles, I'll add that there are two ways to do this due to the properties of De Morgan's Law.
First, meaning "if it is not an iPhone and it is not an iPod" (as posted in the other answer):
if((!navigator.userAgent.match(/iPhone/i)) && (!navigator.userAgent.match(/iPod/i))) {
// Do something
}
And second, meaning "if it is not an iPhone or an iPod", which is just a logical negation of the entire current statement:
if(!(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i))) {
// Do something
}
if((!navigator.userAgent.match(/iPhone/i)) && (!navigator.userAgent.match(/iPod/i))) {}
Use this line here:
var isiOS = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)/i) != null ? true : false;
精彩评论