| 
| 
 
| 
  
    | 
      
        | js获取客户端系统已安装的所有字体  |  
        | 
          
            |  |  
            | 来源:互联网  作者:phperz.com 整理  发布时间:2008-01-07 |  
            |  |  |  
        
          | 如何获取客户端系统已安装的所有字体?
 以下代码在IE下测试有效,如果你想看效果可复制以下代码另存为 "系统字体.html "  的静态文件。
 
 
 
    
        
            | 以下为引用的内容: <html>
 <head>
 </head>
 <body>
 <DIV style="LEFT: 0px; POSITION: absolute; TOP: 0px">
 <OBJECT ID="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" WIDTH="0px" HEIGHT="0px"></OBJECT>
 <script language="javascript" type="text/javascript">
 // FontFacesMenu.js
 var fontsArray = new Array();
 var fontsIsAdded = false; PHP程序员站
 function fontFacesMenuEnter(fontFacesDropdownList, dlgHelperId)
 {
 if((fontsIsAdded == false )||(fontsArray==''))
 {
 fontsArray = getSystemFonts(dlgHelperId);
 
 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;
 }
 </script>
 </DIV>
 <select id="blessingWords_FontFamily_DL" name="blessingWords_FontFamily_DL" style="width:140px;" onmouseenter="fontFacesMenuEnter(this, 'dlgHelper');//updateFontList();">
 PHP程序员站--PHP程序员之家 <option value=""><- 设置字体 -></option>
 </select>
 </body>
 |  运行效果如图:
 
 
  
 下面我们一步一步来做
 1.首先在需要获取系统字体的网页<body>后加入以下代码:
 
 
 
    
        
            | 以下为引用的内容: <DIV style="LEFT: 0px; POSITION: absolute; TOP: 0px">
 <OBJECT ID="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" WIDTH="0px" HEIGHT="0px"> www phperz com
 </OBJECT>
 <script src="FontFacesMenu.js" language="javascript" type="text/javascript"></script>
 </DIV>
 |  2.将以下内容保存为:FontFacesMenu.js文件。
 
 
 
    
        
            | 以下为引用的内容: // FontFacesMenu.js
 var fontsArray = new Array();
 var fontsIsAdded = false;
 function fontFacesMenuEnter(fontFacesDropdownList, dlgHelperId)
 {
 if((fontsIsAdded == false )||(fontsArray==''))
 {
 fontsArray = getSystemFonts(dlgHelperId);
 
 fontsIsAdded = true;
 for (var s=1; s < fontsArray.length; s++)
 PHP程序员站--PHP程序员之家 {
 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;
 }
 phperz.com |  3.在网页需要插入字体下拉菜单的位置处插入以下代码:
 
 系统字体:
 
 
 
    
        
            | 以下为引用的内容: <SELECT ID="blessingWords_FontFamily_DL" name="blessingWords_FontFamily_DL" style="width:140px;" onmouseenter="fontFacesMenuEnter(this, 'dlgHelper');//updateFontList();">
 <OPTION VALUE=""><- 设置字体 -></OPTION>
 </SELECT>
 |  
 OK!看到效果了没有?如图:
 
  www~phperz~.com 注:如果需要加上选中后的事件,在onChange中改变成你自己的相应事件处理即可。
 
 
 |  
          | 共2页: 上一页 1 [2] 下一页 |  
          | [收藏此页] [打印本页] [返回顶部] |  |  
    |  |  |   
|  |   
|  |  |  |  |  |