Get pseudo-element background styles

Internet Explorer 8 does not allow printing background images.
Unfortunately, I was asked to do this job.

Some pseudo-elements that should be printable have “important” images.
I thought that it would be possible to turn these background images into elements <img/> however it seems that it is impossible to read pseudo-element styles in Internet Explorer 8 because it does not support getComputedStyle.

Any good ideas?

Related :
https://developer.mozilla.org/en/docs/Web/API/window.getComputedStyle
http://caniuse.com/getcomputedstyle/embed
SO "Getting pseudo-element style values"

+4
source share
1 answer

This should work:

var img = window.getComputedStyle(
    document.querySelector('.element'), ':before'
).getPropertyValue('background');

Change . I have a working fiddle that doesn't use querySelector:

var img = window.getComputedStyle(
    $(".element")[0], ':before'
).getPropertyValue('background');

Basically, you just want to get the element as the first parameter in getComputedStyle;

But this still does not fix the requirement of IE 8, since it getComputedStyleis not supported there ... However, this question may provide an answer there.

+3
source

Source: https://habr.com/ru/post/1524683/


All Articles