Load content if operating system is everything but linux

Hi,

I am trying to load some code depending on what operating system the users are using. I basically want to load the content on all operating systems except linux.

This is the code I have so far, but I am not too sure how to go about it and if it will work:



if (navigator.appVersion.indexOf("Linux")!=-1){
//hide the following code from Linux

LoadFlash : function(flash_path, width, height){
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ width +'" height="'+ height +'">');
		document.write('<param name="movie" value="'+ flash_path +'"/><param name="quality" value="best"/><param name="wmode" value="transparent"/><param name="play" value="true"/><embed pluginspage="http://www.macromedia.com/go/getflashplayer" src="'+ flash_path +'" type="application/x-shockwave-flash" wmode="transparent" quality="best" play="true" width="'+ width +'" height="'+ height +'"></embed>');
		document.write('</object>');
	}


}

else {
  //load the code for all other operating systems

 LoadFlash : function(flash_path, width, height){
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ width +'" height="'+ height +'">');
		document.write('<param name="movie" value="'+ flash_path +'"/><param name="quality" value="best"/><param name="wmode" value="transparent"/><param name="play" value="true"/><embed pluginspage="http://www.macromedia.com/go/getflashplayer" src="'+ flash_path +'" type="application/x-shockwave-flash" wmode="transparent" quality="best" play="true" width="'+ width +'" height="'+ height +'"></embed>');
		document.write('</object>');
	}
}


I am not sure how to hide the content in the if statement.

Any ideas?

Thanks!

Firstly, get away from using document.write. It’s rarely a good idea to use document.write or document.writeln. Create an element, give it a unique ID, and use the DOM to display.

I’m so anal-retentive that I would set a variable to the navigator.appVersion, trim it, push it to all lower-case, and THEN go for the comparison.

The conditional looks correct, to me. Are you getting a console error message? Is it breaking?

This Javascript, not PHP.

I suggested using this method in your other thread just a second ago. I didn’t see this one.


if (navigator.appVersion.indexOf("Linux")!=-1){ 

That works fine and is probably your only option client side.

There is a very similar thread by this OP here: http://www.sitepoint.com/forums/showthread.php?1218699-hide-content-from-linux-users

Please all refer to that thread.

This thread is hereby closed.