1

I have tried all the solutions from the below link but I couldn't make it work. How can I detect browser type using jQuery?

$(document).ready(function(e) {
    $.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); 
    if($.browser.chrome){
        alert(1);
             //this work well
    }
            else if(//the browser is IE){alert(2);}
            else if(//the browser is Firefox){alert(3);}

 )};

Thanks.

1
  • Why you want to know the browser? And posting the exact same question as in another, already answered, question cries for a duplicate-closure. Instead show your actual code which doesn't work and we might be able to help you. Commented Oct 1, 2016 at 12:17

1 Answer 1

1

$.browser is depreciated so you may have to use migrate plugin as mentioned in: https://api.jquery.com/jquery.browser/

Checking browser may not be relevant anymore, have a look at: http://webaim.org/blog/user-agent-string-history/

You may use window.navigator.appVersion if you want to still detect browser.

I could see window.navigator.appVersion returned below to me:

IE: "5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E; GWX:RESERVED; rv:11.0) like Gecko"

Mozilla: "5.0 (Windows)"

Chrome: "5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.