The below script checks whether the particular font is installed in the client browser or not.
<script language = ‘javascript’ >
function checkIfInstalled(fname)
{
IE4 = document.all;
NS4 = document.layers;
ver4 = (IE4 || NS4);
if(!ver4) return false;
isMac = (navigator.appVersion.indexOf("Mac") != -1);
isWin = (navigator.appVersion.indexOf("Win") != -1);
arNotNavWin = ["Webdings","Marlett"];
if(NS4 && isWin)
{
for(i=0;i<arNotNavWin.length;i++)
{
if (fname == arNotNavWin[i]) return false;
}
}
teststr = "font existence test"
if(IE4)
{
if(!window.fntLyr0)
{
lyrstr0 = "<SPAN ID=fntLyr0 STYLE='position:absolute;visibility:hidden;width:30;font:12pt Courier'>"+ teststr +"</SPAN>";
lyrstr1 = "<SPAN ID=fntLyr1 STYLE='position:absolute;visibility:hidden;width:30;font-size:12pt'>"+ teststr +"</SPAN>";
document.body.insertAdjacentHTML("BeforeEnd",lyrstr0);
document.body.insertAdjacentHTML("BeforeEnd",lyrstr1);
}
fntLyr1.style.fontFamily = fname +",Courier";
width0 = (isMac) ? fntLyr0.offsetWidth : fntLyr0.scrollWidth;
width1 = (isMac) ? fntLyr1.offsetWidth : fntLyr1.scrollWidth;
}
if(NS4)
{
lyrstr1 = "<FONT FACE='"+ fname +",Courier' POINT-SIZE=12>"+ teststr +"</FONT>";
if(!window.fntLyr0)
{
lyrstr0 = "<FONT FACE='Courier' POINT-SIZE=12>"+ teststr +"</FONT>";
fntLyr0 = new Layer(400);
fntLyr0.document.write(lyrstr0);
fntLyr0.document.close();
fntLyr1 = new Layer(400);
fntLyr1.document.write(lyrstr1);
fntLyr1.document.close();
}
else
{
fntLyr1.document.write(lyrstr1);
fntLyr1.document.close();
}
width0 = fntLyr0.clip.width;
width1 = fntLyr1.clip.width;
}
return (width0 != width1)? 'Installed' : 'Not installed';
}
</script>
Code to call the script function.
<h1>Check the Font installed or not</h1>
<input id = 'txtFont' name = 'txtFont' value = 'Arial' >
<input type = 'button' value = 'IsInstalled'
onclick ="alert(checkIfInstalled(txtFont.value))" />
Visit to check this script.
No comments:
Post a Comment