Hide content based on OS

The code example below hides some hyperlinks based on the users operating system
HTML • JavaScript

1) the style tag in each DIV tag hides each link by default.

2) The togglelink function in the onload event determines which link should be made visible.

<script>
// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors 
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

function togglelink(){
	if (OSName=='MacOS'){
		//show
	    document.getElementById("MacLink").style.display='';
		//hide
	    document.getElementById("WindowsLink").style.display='none';
	}
	else{
		//show
	    document.getElementById("MacLink").style.display='none';
		//hide
	    document.getElementById("WindowsLink").style.display='';
	}
}

</script>


<body onload='togglelink();'  topmargin="0" leftmargin="0">

<div id="WindowsLink" style="display='none'" align="center">CONTENT HERE</div> 

<div id="MacLink" style="display='none'" align="center">CONTENT HERE</div> 

</body>

Posted by fbrefere001 on Wednesday February 22, 2006