martes, 12 de febrero de 2013

Error java script con Report Viewer e Internet Explorer 9 (window.getComputedStyle)

Contexto

Página con ReportViewer en Internet Explorer 9,

Sintomas

Aparece un "Error en tiempo de ejecución de Microsoft jscript, Interfaz no compatible" al desplegar una de las listas de criterios.
El error esta relacionado con la función window.getComputedStyle.

Solución

Fuente: MikeHoffer en un articulo de Microsoft Community
  1. Prepara la página para usar jquery si aún no existe.
  2. Inserta el siguiente código en la sección de cabecera.
<!-- IE 9 throws an error when this is called, so we need to override it and catch that error -->
    <!--[if IE 9]>
    <script language="javascript" type="text/javascript">
        $(window).ready(function () {
            window.getComputedStyle = function (el, pseudo) {
                this.el = el;
                this.getPropertyValue = function (prop) {
                    var re = /(\-([a-z]){1})/g;
                    if (prop == 'float') prop = 'styleFloat';
                    if (re.test(prop)) {
                        prop = prop.replace(re, function () {
                            return arguments[2].toUpperCase();
                        });
                    }
                    //error occures on the currentStyle
                    //return el.currentStyle[prop] ? el.currentStyle[prop] : null;
                    if (typeof(el.currentStyle) == 'undefined') {
                        return null;
                    } else {
                        return el.currentStyle[prop] ? el.currentStyle[prop] : null;
                    }
                }
                return this;
            }
        })        
    </script>
    <![endif]-->

No hay comentarios: