Some ?useful script.

I post this code to this list with some trepidation. The only thing which
prompts me to do so is that last night while talking to a friend who I
assumed to be (in fact is) much more knowledgeable that I am he said "If
only there was someway we could write different style-sheets for the
different versions..".

Well here is the code I have been using for sometime now.(Paste it in
notepad, it looks much better!!)

As I say if this is to trivial for this list I appologise.

Frank Boumphrey.

<HTML>
<HEAD>

<SCRIPT>
 //This script loads diferent style sheets for different browser versions.
 //Author Frank Boumphrey
 //e-mail:-Bckman@ix.netcom.com
 //Written 11/5/97
 //Last revised 3:59 PM 3/13/98
 //////////////////////////////////////////////////////////
 //this function returns the version type of the browser //
 //1e4 if IE4 or greater     //
 //nav if Navigator4 or greater    //
 //other if none of the above    //
 //////////////////////////////////////////////////////////
function vertype(){

 //////////////////////////////////////////////////////////
 //this function returns the version type of the browser //
 //1e4 if IE4 or greater     //
 //nav if Navigator4 or greater    //
 //other if none of the above    //
 //////////////////////////////////////////////////////////
//declare function variables
 var browType=""
 var vnum=""
 var isie4

//load function variables
 browType=navigator.appName;
//returns first character of appVersion(which is the version number)
 vnum=navigator.appVersion.charAt(0);

 if(browType=="Microsoft Internet Explorer" && vnum > 3)
  {
  isie4="ie4";
  }
 else if(browType=="Netscape" && vnum > 3)
  {
  isie4="nav";
  }
 else
  {
  isie4="other";
  //Use a confirm to reroute others or tell them to get lost!!
   if(confirm("This browser probably does not support dynamic HTML.\nClick
OK to go to our non-dhtml website.\nClick Cancel to continue here.")==true)
   {location.href="intro1.htm";}
  }
 return isie4
}


function writestyle(e){
 //////////////////////////////////////////////////////////
 //this function writes different stylesheets for the  //
 //different browser versions    //
 //////////////////////////////////////////////////////////

 if(e=="ie4")
  {
  //write the style sheet for IE4
  document.write("<STYLE>.ie4{color:navy; font-size:32pt;
font-style:italic;}</STYLE>");
  }
 if(e=="nav")
  {
  //write the style sheet for Navigator4.
  //Also demonstrates how to split between lines.
  document.write(
  "<STYLE>.nav{color:blue;"
   +" font-size:24pt;"
   +"font-style:bold;}"
  +"</STYLE>");
  }
 if(e=="other")
  {
  //note this alert still appears even if you select OK in alert above in
vertype().
  alert("No styling is being applied to this document");
  }

 return ;
}

//the following code calls the functions
 var browtype=vertype();

 var e=writestyle(browtype);
</SCRIPT>
</HEAD>
<BODY>
<DIV CLASS="ie4">This text will be in Navy 32 point italic script if being
run on IE4 or higher.</DIV>
<DIV CLASS="nav">This text will be in Blue 24 point bold script if being run
on Navigator4 or higher.</DIV>
</BODY>
</HTML>

Received on Friday, 13 March 1998 16:04:44 UTC