Good day - the question is this: is there a ready-made solution that allows for checks like this:

if(mobileBrowser) {} else {/* desktop browser */} 

Interested in both the server and the client.

I found only this on php

And in general - who uses what for these purposes?


especially relevant solution to JS.

upd is another option - Yandex Director , but I really wouldn’t like to make unnecessary requests ...

Marked as a duplicate by mymedia participants, aleksandr barakin , 0xdb , LFC , Yaroslav Molchan on April 16 at 8:52 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    I used the solution provided from here , almost all the necessary implementations. Used under the python, not much corrected regulars, but it seems to work correctly.

    • Thank you very much what you need. - Zowie
     /* ------------------------ * * CSS Browser Selector 4.0 * * ------------------------ */ function css(u){ var ua=u.toLowerCase(), is=function(t){ return ua.indexOf(t)>-1 }, g='gecko', w='webkit', s='safari', o='opera', m='mobile', h=document.documentElement, b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))? ('ie ie'+RegExp.$1):is('firefox/2')? g+' ff2':is('firefox/3.5')? g+' ff3 ff3_5':is('firefox/3.6')? g+' ff3 ff3_6':is('firefox/3')? g+' ff3':is('gecko/')? g:is('opera')? o+(/version\/(\d+)/.test(ua)? ' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)? ' '+o+RegExp.$2:'')):is('konqueror')? 'konqueror':is('blackberry')? m+' blackberry':is('android')? m+' android':is('chrome')? w+' chrome':is('iron')? w+' iron':is('applewebkit/')? w+' '+s+(/version\/(\d+)/.test(ua)? ' '+s+RegExp.$1:''):is('mozilla/')? g:'',is('j2me')? m+' j2me':is('iphone')? m+' iphone':is('ipod')? m+' ipod':is('ipad')? m+' ipad':is('mac')? 'mac':is('darwin')? 'mac':is('webtv')? 'webtv':is('win')? 'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')? 'freebsd':(is('x11')||is('linux'))? 'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c; }; css(navigator.userAgent); 
    • And thank you =) - Zowie