Hi guys, I have a relatively basic JS question. Using navigator.appName, how can I tell a chrome user apart from a Firefox user? The value is the same for both browsers, as you can see here-- So how do I tell them apart? Thanks, -Tony
I don't want to use jquery because it just makes coding slightly easier in exchange for loading an additional 200k on page loads. Any pure JS solutions? Thanks, -Tony
the variable you will need is window.navigator.userAgent Code (markup): you can test multiple browsers, here are example outputs. Chrome: Firefox: Opera: So the key words are: Chrome, Safari, Firefox, Opera: var isFirefox = function(){ return window.navigator.userAgent.toLowerCase().indexOf("firefox")>=0; }; var isChrome = function(){ return window.navigator.userAgent.toLowerCase().indexOf("chrome")>=0; }; var isOpera = function(){ return window.navigator.userAgent.toLowerCase().indexOf("opera")>=0; }; var isSafari = function(){ return window.navigator.userAgent.toLowerCase().indexOf("safari")>=0 && !isChrome(); }; Code (markup): but is better to do detection of functions (in case you are doing some browser optimisation): if (typeof myFunction == 'function' ) { myFunction(); } Code (markup):
I think I understand what you mean... But how would these functions return true or false if there is no if statement? (from your post) -Tony