PHPology is a collective of highly skilled, award winning, web gurus.
Contact Raj on 07985 467 213 or email [email protected]

Javascript browser detection script

Simple javascript browser detection script

//check browser version and base action against it if required. In our case, we want IE7 and below to redirect to ie fallback html page
navigator.sayswho = (function(){
	  var N= navigator.appName, ua= navigator.userAgent, tem;
	  var M= ua.match(/(opera|chrome|safari|firefox|msie)/?s*(.?d+(.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;
})();
var browser = navigator.sayswho[0];
var browser_version = navigator.sayswho[1];
//print out values
console.log(browser);
console.log(browser_version);
switch(browser)
{
	case "MSIE":
		if(parseInt(browser_version) <= 7)
		{
			//window.location.href = 'advocates_ie_fallback.html';
		}
	break;
	default:
	break;
}