How do I get all the fonts that are installed on the client system in a Web page?

Source: Internet
Author: User

How to get system fonts.
1. First after you need to get the System font page <body> add the following code:
<div style= "left:0px; Position:absolute; top:0px ""
<object id= "Dlghelper" classid= "clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" WIDTH= "0px" HEIGHT= "0px"
</object>
<script src= "Fontfacesmenu.js" language= "JavaScript" type= "Text/javascript" ></script>
</DIV>

2. Save the following content as: Fontfacesmenu.js file.
//Fontfacesmenu.js
var fontsarray = new Array ();
var fontsisadded = false;
Function Fontfacesmenuenter (fontfacesdropdownlist, Dlghelperid)
{
 if (fontsisadded = false) | | (fontsarray== '))
 {
  fontsarray = getsystemfonts (Dlghelperid);
&NBSP;&NBSP
  fontsisadded = true;
  for (Var s=1 s < fontsarray.length; s++)
  {
   newoption = Document.createelement ("option");
   newoption.value = Fontsarray[s];
   newoption.text = Fontsarray[s];
   fontfacesdropdownlist.add (newoption);
  }
 }
}

function Getsystemfonts (Dlghelperid)
{
var a = document.all (Dlghelperid). Fonts.count;
var farray = new Array ();
for (i = 1;i <= parent.document.all (dlghelperid). fonts.count;i++) {
Farray[i] = Parent.document.all (Dlghelperid). fonts (i);
}
return farray;
}

3. Insert the following code where you want to insert a font drop down menu:

System fonts:
<select id= "Blessingwords_fontfamily_dl" name= "Blessingwords_fontfamily_dl" onchange= "//SetFontFace" (this[ This.selectedindex].innertext,this[this.selectedindex].value); this.selectedindex=0; "style=" width:140px; " Onmouseenter= "Fontfacesmenuenter (This, ' dlghelper ');//updatefontlist ();" >
<option value= "" ><-set font-></option>
</SELECT>

Ok. See the effect of No. If you can, congratulations.
Note: If you need to add the selected event, change it to your own event handling in onchange.
The above is useful for client development, if you need server-side fonts, continue to look down, or skip it.

4. How to save my system font as a file. (slightly smaller for server-side development)
(1) If your server's font configuration is the same as your existing computer font configuration, use JavaScript script, and then copy to WordPad or Notepad, and then save.
continue with the steps above:
(cont.) Step One: Place the following code in the <Body> area:
<textarea name= "fontlist" id= "fontlist" cols= "rows=" 20 "Id=" Fontlist "style=" Position:absolute; left:0px; top:0px; z-index:10000 "></textarea>
Step two:
<script>
//" BLESSINGWORDS_FONTFAMILY_DL " You need to change it to yourself. Gets the name of the system font drop-down menu (if you have changed)
var dropdownlistname = "Blessingwords_fontfamily_dl";
function Updatefontlist ()
{
 var list= "";
 var blessingwords_fontfamily_dl = Document.all[dropdownlistname];
 for (i=0 i <blessingWords_FontFamily_DL.options.length; i++)
 {
  list + = ' < Option value= "' + Blessingwords_fontfamily_dl.options[i].text + '" > ' + blessingwords_fontfamily_dl.options[i].text + ' </option>/r/n ';
 }
 document.all ("Fontlist"). Value = list;
}
</Script>

Step three: The Last "//updatefontlist ()" in article 3rd above; The two slashes are hidden and become:
Onmouseenter= "Fontfacesmenuenter (This, ' dlghelper '); Updatefontlist ();"

Step Four: Save your Web page, refresh it, and try again. In the "fontlist" textarea area you should already have all your system fonts, copy and paste to the place you need.
For example: The 3rd article <option value= "" ><-set font-></option> below, so that You can turn it into a related font on the server (if your server's font configuration is the same as your existing computer font configuration).
(2) Use C # code to get the fonts in the server system (temporarily skipped, and then written). The advantage is that you can get the server-side fonts directly to keep the development consistent.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.