JavaScript OS Detection


I made this to display a compatibility warning message on a page I was working on, but later removed it after it was discovered that the compatibility issue didn’t actually exist. Regardless, it is often handy to determine what OS someone is running:

<p id="compatibilityWarning" class="error" style="color:#FF0000" style="display:none;"></p>
<script>
<!--
// Lets make sure that they have an OS that we can actually provide service for
function compatibilityCheck(){
	var OSName="Unknown OS";
	if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
	if (navigator.appVersion.indexOf("Mac")!=-1) OSName="Apple or Macintosh";
	if (navigator.appVersion.indexOf("X11")!=-1) OSName="Linux or Unix";
	if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux or Unix";

	if(OSName != "Windows"){
		document.getElementById('compatibilityWarning').innerHTML='<strong>Please be aware that the service is not compatible with '+OSName+'.  If you are using '+OSName+', we will be unable to provide service.</strong><br />';
		document.getElementById('compatibilityWarning').style.display='block';
	}else{
		if (navigator.userAgent.indexOf("Windows NT 6.0") > -1) {
			document.getElementById('compatibilityWarning').innerHTML='<strong>Please be aware that the service is not compatible with Windows Vista. If you are using Windows Vista, we will be unable to provide service.</strong><br />';
			document.getElementById('compatibilityWarning').style.display='block';
		}
	}

	return true;
}
compatibilityCheck();
//-->
</script>

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>