有什么方法可以检测正在使用的 Windows XP 主题吗?
我怀疑您无法进行特定的 api 调用,但您可以通过检查某些 DOM 元素(即特征检测)来找出答案。
另一个问题:经典主题甚至存在于 windows vista 或 windows 7 上吗?
编辑 - 这是我的解决方案:
function isXpTheme() {
var rgb;
var map = { "rgb(212,208,200)" : false,
"rgb(236,233,216)" : true };
var $elem = $("<button>");
$elem.css("backgroundColor", "ButtonFace");
$("body").append($elem);
var elem = $elem.get(0);
if (document.defaultView && document.defaultView.getComputedStyle) {
s = document.defaultView.getComputedStyle(elem, "");
rgb = s && s.getPropertyValue("background-color");
} else if (elem.currentStyle) {
rgb = (function (el) { // get a rgb based color on IE
var oRG =document.body.createTextRange();
oRG.moveToElementText(el);
var iClr=oRG.queryCommandValue("BackColor");
return "rgb("+(iClr & 0xFF)+","+((iClr & 0xFF00)>>8)+","+
((iClr & 0xFF0000)>>16)+")";
})(elem);
} else if (elem.style["backgroundColor"]) {
rgb = elem.style["backgroundColor"];
} else {
rgb = null;
}
$elem.remove();
rgb = rgb.replace(/[ ]+/g,"")
if(rgb){;
return map[rgb];
}
}
下一步是弄清楚这个函数在非 xp 机器上返回什么和/或弄清楚如何检测 windows 框。我只在 windows XP 中测试过,所以 vista 和 windows 7 可能会给出不同的颜色值,但应该很容易添加。
这是一个实际的演示页面: