Reputation: 26
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.
Upvotes: 1
Views: 2311
Reputation: 11
$.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"
Upvotes: 1