Javascript compatibility does not work in IE

I have the following code.

function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

It seems to work fine in FF and Chrome. IE has "1", it is null or not an object. The rgb value seems to refer to rgb.match.

Any ideas?

thank

+3
source share
1 answer

Try printing what rgb is before running a regular expression. It is possible that the input is different.

I assume that you are checking the property dom_element.style. Perhaps IE will never convert this property to format rgb(r, g, b)in the first place.

+3
source

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


All Articles