jerkovicl
5/30/2015 - 5:19 PM

Browser Feature Detection

Browser Feature Detection

if('querySelector' in document
     && 'localStorage' in window
     && 'addEventListener' in window) {
     // Modern browser. Let's add JavaScript functionality
     }
/*
With this in place, we have two groups of browsers, 
modern (IE9+, Fx, Safari, Opera, Chrome, iOS, Android 2.1+, …) 
and old (IE8-, Blackberry, …).
*/

// detection extended with support for ServiceWorker availability
if ('visibilityState' in document) { 
	// Modern browser. Let's load JavaScript
	if ('serviceWorker' in navigator) {
		// Let's add offline support
		navigator.serviceWorker.register('sw.js', {
			scope: './'
		});
	}
}