I am trying to detect the chrome and safari browser using jquery or javascript.
I thought we are not supposed to use jQuery.browser. Are there any suggestions here? Thanks a lot!
I am trying to detect the chrome and safari browser using jquery or javascript.
Share
If you dont want to use
$.browser, take a look at case 1, otherwise maybe case 2 and 3 can help you just to get informed because it is not recommended to use$.browser(the user agent can be spoofed using this). An alternative can be usingjQuery.supportthat will detect feature support and not agent info.But…
If you insist on getting browser type (just Chrome or Safari) but not using
$.browser, case 1 is what you looking for…This fits your requirement:
Case 1: (No jQuery and no $.browser, just javascript)
Live Demo: http://jsfiddle.net/oscarj24/DJ349/
These cases I used in times before and worked well but they are not recommended…
Case 2: (Using jQuery and $.browser, this one is tricky)
Live Demo: http://jsfiddle.net/oscarj24/gNENk/
Case 3: (Using jQuery and $.browser, “elegant” solution)
Live Demo: http://jsfiddle.net/oscarj24/uJuEU/