faqts : Computers : Programming : Languages : JavaScript : Browser Settings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

73 of 78 people (94%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Internet: Browser: How to determine if Microsoft Internet Explorer or not?

Jan 19th, 2006 00:07
Guido Hein, Knud van Eeden,


I created a function that will detect Netscape, MSIE, Opera, Mozilla and
Firefox with Version Information. 

function chkBrowser(){
  var chkAgent1=navigator.userAgent;
  var chkVersion=navigator.appVersion.substring(0,3);
  var IE=chkAgent1.search(/MSIE/i);
  var Netscape=chkAgent1.search(/Netscape/i);
  var Opera=chkAgent1.search(/Opera/i);
  var Mozilla=chkAgent1.search(/Mozilla/i);
  var compatible=chkAgent1.search(/compatible/i);
  var Firefox=chkAgent1.search(/Firefox/i);
  var Gecko = chkAgent1.search(/Gecko/i);

  if (IE != -1 && compatible != -1 && Mozilla != -1 && Netscape == -1 &&
chkVersion == "4.0" ){
  	Browser = "MSIE";
	var startpos = navigator.userAgent.search(/MSIE/i);
	var startid = startpos + 5;
	var end = startpos + 8;
	getVersion = navigator.userAgent.substring(startid,end);
	document.write(Browser + getVersion);
  }
  if (Opera != -1 && Mozilla != -1 && compatible != -1){
	Browser = "Opera";
	var startpos = navigator.userAgent.search(/Opera/i);
	var startid = startpos + 6;
	var end = startpos + 10;
	getVersion = navigator.userAgent.substring(startid,end);
	document.write(Browser + getVersion);
  }
  if (Mozilla != -1 && Firefox == -1 && chkVersion == "5.0" &&
compatible == -1 && Netscape == -1){
  	Browser = "Mozilla";
	var startpos = navigator.userAgent.search(/rv/i);
	var startid = startpos + 3;
	var end = navigator.userAgent.search(/G/i);
	var endpos = end -2;
	getVersion = navigator.userAgent.substring(startid,endpos);
	document.write(Browser + getVersion);
  }
  if (Mozilla != -1 && Firefox != -1 && chkVersion == "5.0"  &&
compatible == -1 && Netscape == -1){
  	Browser = "Firefox";
	var startpos = navigator.userAgent.search(/rv/i);
	var startid = startpos + 3;
	var end = navigator.userAgent.search(/G/i);
	var endpos = end -2;
	getVersion = navigator.userAgent.substring(startid,endpos);
	document.write(Browser + getVersion);
  }
  if ((Mozilla != -1 && chkVersion == "4.8")){
  	Browser = "Netscape";
	getVersion = "4.8";
	document.write(Browser + getVersion);
  }
  
  if (Netscape != -1){
  	Browser = "Netscape";
	var startpos = navigator.userAgent.search(/Netscape/i);
	var startid = startpos + 9;
	var end = startpos + 12;
	getVersion = navigator.userAgent.substring(startid,end);
	document.write(Browser + getVersion);

  }
}