getComputedStyle like javascript function for IE8

gwt, internet-explorer-8, javascript

Solution

I used a similar method to my original solution with an additional case to handle inline styles, also the way to check if the current document support the `getComputedStyle` is a bit different it checks in the `document.defaultView` instead of the window itself, here is the full function

public static native String getStyleProperty(Element el, String prop) /*-{
        var computedStyle;
        if (document.defaultView && document.defaultView.getComputedStyle) { // standard (includes ie9)
            computedStyle = document.defaultView.getComputedStyle(el, null)[prop];

        } else if (el.currentStyle) { // IE older
            computedStyle = el.currentStyle[prop];

        } else { // inline style
            computedStyle = el.style[prop];
        }
        return computedStyle;

    }-*/;

source

Problem

I'm trying to write a Javascript function inside a Java GWT code that gets the value of the following styles ``` "direction", "fontFamily", "fontSize", "fontSizeAdjust", "fontStyle", "fontWeight", "letterSpacing", "lineHeight", "padding", "textAlign", "textDecoration", "textTransform", "wordSpacing" ``` The `getComputedStyle` was useful in all browsers except IE8 which doesn't support such function as I understand I looked at the posts about smiler subject here but all of them failed to get one of the above styles smiler subject posts 1, 2. Here is my initial solution without the IE8 special case ``` public static native String getStyleProperty(Element element, String style) /*-{ if (element.currentStyle) { return element.currentStyle[style]; } else if (window.getComputedStyle) { return window.getComputedStyle(element, null).getPropertyValue( style); } }-*/; ``` Any suggestions for a good `getComputedStyle` replacement function for IE8 ?

Original source

Related problems