【javascript】Convert any colour value to hex in MSIE
2012-07-12 14:07
393 查看
The following function will convert any colour value (rgb, named colours, etc) to the hex equivalent in MSIE:
function toHex(color) {
var body = createPopup().document.body,
range = body.createTextRange();
body.style.color = color;
var value = range.queryCommandValue("ForeColor");
value = ((value & 0x0000ff) << 16) | (value & 0x00ff00) | ((value & 0xff0000) >>> 16);
value = value.toString(16);
return "#000000".slice(0, 7 - value.length) + value;
};
For other browsers you can use
function toHex(color) {
var body = createPopup().document.body,
range = body.createTextRange();
body.style.color = color;
var value = range.queryCommandValue("ForeColor");
value = ((value & 0x0000ff) << 16) | (value & 0x00ff00) | ((value & 0xff0000) >>> 16);
value = value.toString(16);
return "#000000".slice(0, 7 - value.length) + value;
};
For other browsers you can use
getComputedStyle()so that is already a solved problem.
相关文章推荐
- JSP中出现According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expression
- JSP中出现According to TLD or attribute directive in tag file, attribute value does not accept any expre
- 解决:According to TLD or attribute directive in tag file, attribute value does not accept any express。
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- 解决:According to TLD or attribute directive in tag file, attribute value does not accept any express。
- Exception:According to TLD or attribute directive in tag file, attribute value does not accept any expression
- 使用JSTL tag时出现错误:According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- EL表达式报错: According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- Troubleshooting - Exception: According to TLD or attribute directive in tag file, attribute value does not accept any expressions.
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions异常原因及解决方法
- 错误:According to TLD or attribute directive in tag file, attribute value does not accept any expressions