博客园  :: 首页  :: 新随笔  :: 订阅 订阅  :: 管理

IE下获取所有客户端字体,设置背景色

Posted on 2011-10-20 17:36  PHP-张工  阅读(626)  评论(0编辑  收藏  举报

此功能只可在IE下使用。

博客园不提供使用 OBJECT 所以就无法在线演示了。

代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
</head>
<body>
<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px">
</OBJECT>
<input type="button" value="获取所有字体" onclick="getFont();" />
<input type="button" value="设置背景色" onclick="callColorDlg();" />
<script type="text/javascript">
function getFont()
{
var a=dlgHelper.fonts.count;
alert(a);
//show total number of system fonts
for (i = 1;i < dlgHelper.fonts.count;i++)
{
var f= f + " " + dlgHelper.fonts(i)
}
alert(f);
//show names of all system fonts
}

var sInitColor = null;
function callColorDlg(){

if (sInitColor == null)
var sColor = dlgHelper.ChooseColorDlg();
else
var sColor = dlgHelper.ChooseColorDlg(sInitColor);

sColor
= sColor.toString(16);
if (sColor.length < 6) {
var sTempString = "000000".substring(0,6-sColor.length);
sColor
= sTempString.concat(sColor);
}
sInitColor
= sColor;
document.body.style.backgroundColor
= '#' + sColor;
}

</script>
</body>
</html>