Computer Science Canada

Java script useful function

Author:  Homer_simpson [ Wed Aug 13, 2003 1:09 pm ]
Post subject:  Java script useful function

I got this function from a tutorial it seems pretty useful so i post it here:

code:
function checkIfInstalled(fname){
   loaded = document.readyState == "complete";
   teststr = "font existence test"
   if(!window.fntLyr0) {
      lyrstr0 = "<SPAN ID=fntLyr0 STYLE='position:absolute;width:30;font:12pt Courier'>"+ teststr +"</SPAN>";
      lyrstr1 = "<SPAN ID=fntLyr1 STYLE='position:absolute;width:30;font-size:12pt'>"+ teststr +"</SPAN>";
      if (loaded) {
         document.body.insertAdjacentHTML("BeforeEnd",lyrstr0);     
         document.body.insertAdjacentHTML("BeforeEnd",lyrstr1);
      }
      else {
         document.write(lyrstr0);
         document.write(lyrstr1);
      }
   }
   fntLyr1.style.fontFamily = fname +",Courier";
   width0 = (isMac) ? fntLyr0.offsetWidth : fntLyr0.scrollWidth;
   width1 = (isMac) ? fntLyr1.offsetWidth : fntLyr1.scrollWidth;
   return (width0 != width1);
}


fname is the font name that yer checking to see if installed... then function reutrns a boolean to show whether it's installed or not...


: