?

Log in

Updated Browser Name Sniffer - Nothing Is True
Question Yourself

Christopher Parker
Date: 2008-09-23 16:06
Subject: Updated Browser Name Sniffer
Security: Public
Music:Ensiferum - Into Hiding
Tags:code, javascript, programming, web
My browser name sniffer, updated for Google Chrome.

The highlighted section accommodates for the structure of Google Chrome's userAgent string, otherwise Chrome would be detected as Safari:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13

var browserName = navigator.appName;

if (browserName != "Microsoft Internet Explorer" || typeof document.all == "undefined")
{
	if (browserName == "Microsoft Internet Explorer")
		browserName = "your browser"; // for user agent switching capability
	else if (browserName != "Netscape" || navigator.userAgent.indexOf("Netscape") != -1)
		browserName = navigator.appName;
	else
	{
		if ((/\([^)]*\)[^(]*\([^)]*\)[ ]([\w]+?)[\/\s][\d]+?[^;()]+?$/.test(navigator.userAgent))
		 || (/[ ]([\w]+?)[\/\s][\d\.]+?$/.test(navigator.userAgent))
		 || (/[ ]([\w]+?)[\/\s][\d]+?[^;()]+?$/.test(navigator.userAgent))
		 || (/^([\w]+)[\/\s][\d]+.+/.test(navigator.userAgent)))
			browserName = RegExp.$1;
		else
			browserName = navigator.appName;
	}
}
Post A Comment | Share | Link






browse
my journal
links
November 2008