Help with user agent string

I want to do a conditional which says:

if(not safari or android or ios){
do this...

Atm I have:

var firefox = /Firefox/i.test(navigator.userAgent),
    chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); 

if(chrome || firefox){
do this...

But since I want it to work everyhere but safari, android and ios I would rather use a if not condition.

Can anyone help me?

Here is a link on SO regarding checking for IOS (iphone, ipad, ipod).

And here is a list of user agent strings that covers just about everything.



don’t seem enough entries there given the thousands of different browsers that exist.

also it doesn’t cater for when the USER changes it to anything they like - which given that it is there to allow them to identify their browser is at least a possibility. The intended use is to tag your own browser so it doesn’t appear in your stats (or can at least be recognised by your stats)

Relying on useragent for anything other than stats is useless as anyone can set the value to anything (useful for pretending your browser is a different one for sites that are too stupid to realise that there are other browsers that work).

Perhaps; but I’m fairly certain that a very limited number of people actually know how to do this. When it comes to changing browser properties or settings, 99% of users don’t change anything and leave default as is.



That’s why I suggested that it is still useful for stats where a small percentage not being what you expect doesn’t affect things too much.

It is NOT useful for anything else because it will break your site (if not now then as soon as the browser you are trying to detect changes the way it works). You should always test for browser behaviour rather than specific browsers as the next patch to the browser may change its behaviour and just because the browser is claiming to be a particular one doesn’t mean it is.

Most browsers make it very easy to set the useragent to any of the most popular ones so as to get around broken sites that don’t recognise any browser other than IE4 and Netscape 4 (as well as the smaller number that mistakenly check for specific useragents for more recent browsers)…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.