I have a problem in Determining Browsers.
I've tried using navigator
and well, it did not help.
I used alert(navigator.appName);
to determine the browser and I'm currently using Google Chrome
, when the pop up appears it displayed Mozilla
, but in Mozilla
it works fine and with Mozilla
It self.
is there a problem with the code? or it's some bug?
navigator.sayswho= (function(){
var N= navigator.appName, ua= navigator.userAgent, tem,
M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*([\d\.]+)/i);
if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
M= M? [M[1], M[2]]:[N, navigator.appVersion, '-?'];
return M.join(' ');
})();
alert(navigator.sayswho)
It's close to chrome, if you need a simple short solution try to use this:
function getBrowser() {
if( navigator.userAgent.indexOf("Chrome") != -1 ) {
return "Chrome";
} else if( navigator.userAgent.indexOf("Opera") != -1 ) {
return "Opera";
} else if( navigator.userAgent.indexOf("MSIE") != -1 ) {
return "IE";
} else if( navigator.userAgent.indexOf("Firefox") != -1 ) {
return "Firefox";
} else {
return "unknown";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With