Windows 8 User Agent string

May 28th, 2012 by Alex Leave a reply »

Here we go again, with some examples:

Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
Mozilla/5.0 (Windows NT 6.2; rv:10.0) Gecko/20100101 Firefox/10.0
Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11
Mozilla/5.0 (Windows NT 6.2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1 Safari/534.50 
Mozilla/5.0 (Windows NT 6.2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1 Safari/534.50

So it’s pretty simple, let’s wrap up a small function:

function detectWindows8() {
	var os = {};
	var ua = navigator.userAgent;
	if (ua.match(/Windows NT 6.2/i))
		os.windows8 = true;
	return os;
}
 
/// .. later
 
var os = detectWindows8();
if (os.windows8) {
	// do stuff
}

Later on, you can expand the function to detect other OS versions too. Everything’s up to you


Comments are closed.