2010-04-28 11 views
5

He probado esto en Windows XP SP3 en IE7 e IE8 (en todos los modos de compatibilidad) y Windows 7 Ultimate en IE8 (en todos los modos de compatibilidad) y falla de la misma manera en ambos. Estoy ejecutando el último HEAD desde el repositorio couchapp. Esto funciona bien en mi máquina de desarrollo OSX 10.6.3. He probado con Chrome 4.1.249.1064 (45376) y Firefox 3.6 en Windows 7 Ultimate y ambos funcionan bien. Como hacer ambas cosas Safari 4 y Firefox 3.6 en OSX 10.6.3cómo obtener jquery.couch.app.js para trabajar con IE8

Aquí está el mensaje de error

detalles de los errores página web

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; de Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0) Fecha y hora: Miér 28 Abr 2010 03:32:55 GMT

Mensaje: Objeto no lo hace apoyar esta propiedad o método Línea: 159 Char: 7 Código: 0 URI: http://192.168.0.105:5984/test/_design/test/vendor/couchapp/jquery.couch.app.js

y aquí está la "ofender" poco de código, que funciona en Chrome, Firefox y Safari bien. Si dice que el fallo está en la línea que comienza desde el archivo qs.forEach()jquery.couch.app.js

157 var qs = document.location.search.replace(/^\?/,'').split('&'); 
    158 var q = {}; 
    159 qs.forEach(function(param) { 
    160 var ps = param.split('='); 
    161 var k = decodeURIComponent(ps[0]); 
    162 var v = decodeURIComponent(ps[1]); 
    163 if (["startkey", "endkey", "key"].indexOf(k) != -1) { 
    164  q[k] = JSON.parse(v); 
    165 } else { 
    166 q[k] = v; 
    167 } 
    168 }); 
+1

no funciona en IE ... * Ahora ¿dónde he oído eso antes .. .? * –

Respuesta

6

forEach() es una función que se ha añadido recientemente a la especificación JavaScript, por lo que no todos los navegadores soportan.

Usted puede leer sobre él en el MDC: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach

En "Compatibilidad", encontrará un fragmento que hace forEach() disponibles.

if (!Array.prototype.forEach) 
{ 
    Array.prototype.forEach = function(fun /*, thisp*/) 
    { 
    var len = this.length >>> 0; 
    if (typeof fun != "function") 
     throw new TypeError(); 

    var thisp = arguments[1]; 
    for (var i = 0; i < len; i++) 
    { 
     if (i in this) 
     fun.call(thisp, this[i], i, this); 
    } 
    }; 
} 

Copie y pega el código de arriba en su script y forEach() debería funcionar.

+0

esto solo solucionó mi problema parcialmente ya que tuve que agregar 'indexOf' como se menciona en mi respuesta a esta pregunta también. –

0

También he tenido que añadir indexOf() al objeto Array para que funcione después de solucionar el problema forEach()

if (!Array.prototype.indexOf) 
{ 
    Array.prototype.indexOf = function(elt) 
    { 
     var len = this.length >>> 0; 

     var from = Number(arguments[1]) || 0; 
     from = (from < 0) 
       ? Math.ceil(from) 
       : Math.floor(from); 
     if (from < 0) 
      from += len; 

     for (; from < len; from++) 
     { 
      if (from in this && 
       this[from] === elt) 
       return from; 
     } 
     return -1; 
    }; 
} 
Cuestiones relacionadas