Internet Explorer 8 不允许打印背景图像。
不幸的是,我被要求完成这项工作。
一些伪元素中有“重要”的图像,必须是可打印的。
我认为可以将这些背景图像变成 <img/>
元素
然而,在 Internet Explorer 8 中似乎无法读取伪元素的样式,因为它不支持 getComputedStyle
.
有什么好主意吗?
相关:
https://developer.mozilla.org/en/docs/Web/API/window.getComputedStyle
http://caniuse.com/getcomputedstyle/embed
SO "Getting pseudo-element style values"
最佳答案
这应该有效:
var img = window.getComputedStyle(
document.querySelector('.element'), ':before'
).getPropertyValue('background');
编辑:我有一个working fiddle不使用 querySelector
:
var img = window.getComputedStyle(
$(".element")[0], ':before'
).getPropertyValue('background');
基本上,您只想获取一个元素作为 getComputedStyle
中的第一个参数;
但这仍然不能解决 IE 8 的要求,因为那里也不支持 getComputedStyle
... 但是,this question可能会在那里提供答案。
关于javascript - 获取伪元素的背景样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21478770/