Sometimes we just need to know client web browser to deliver information or add some code specific to the browser. In a client web browser navigator object holds client browser name,version,user agent,platform and other details. So we need to extract our requirements from navigator object. Check out this snippet it just do that.
<script type='text/javascript'>
function get_browser(){

var ua= navigator.userAgent, tem, 
    M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=/))/?s*(d+)/i) || [];
        tem=  /rv[ :]+(d+)/g.exec(ua) || [];
       return { name: 'IE ', version: (tem[1] || ''),platform:navigator.platform };
    if(M[1]=== 'Chrome'){
        tem= ua.match(/OPR/(d+)/)
        if(tem!= null) return { name: 'Opera ', version: tem[1],platform:navigator.platform };

    M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
    if((tem= ua.match(/version/(d+)/i))!= null) M.splice(1, 1, tem[1]);
    return  { name: M[0], version: M[1] ,platform:navigator.platform};
var br=get_browser();


Comments (0)
Leave a Comment

loader Posting your comment...