2010-04-28 17 views
5

L'ho provato su Windows XP SP3 in IE7 e IE8 (in tutte le modalità di compatibilità) e Windows 7 Ultimate in IE8 (in tutte le modalità compatiblity) e fallisce allo stesso modo su entrambi. Sto eseguendo l'ultimo HEAD dal repository couchapp. Funziona perfettamente con il mio computer di sviluppo OSX 10.6.3. Ho provato con Chrome 4.1.249.1064 (45376) e Firefox 3.6 su Windows 7 Ultimate ed entrambi funzionano bene. Come fare entrambe le cose Safari 4 e Firefox 3.6 su OSX 10.6.3come ottenere jquery.couch.app.js per funzionare con IE8

Ecco il messaggio di errore

dettagli di errore Webpage

User Agent: Mozilla/4.0 (compatible; MSIE 8.0 ; di 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) Data e ora: Mer 28 apr 2010 03:32:55 UTC

Messaggio: Oggetto non supportare questa proprietà o il metodo Linea: 159 Char: 7 Codice: 0 URI: http://192.168.0.105:5984/test/_design/test/vendor/couchapp/jquery.couch.app.js

ed ecco il "offendere" pezzo di codice, che funziona su Chrome, Firefox e Safari bene. Se dice che il guasto è sulla linea che parte dal file 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

non funziona in IE ... * ora in cui ho sentito che prima .. .? * –

risposta

6

foreach() è una funzione che ha recentemente aggiunto alla specifica JavaScript, quindi non tutti i browser supportano.

Si può leggere su di esso in MDC: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach

Sotto "Compatibilità", troverete un frammento che fa foreach() disponibili.

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); 
    } 
    }; 
} 

Quindi, copia e incolla il codice sopra al tuo script e forEach() dovrebbe funzionare.

+0

questo ha risolto solo parzialmente il mio problema dato che dovevo aggiungere 'indexOf' come menzionato nella mia risposta a questa domanda. –

0

ho anche dovuto aggiungere indexOf() all'oggetto Array per farlo funzionare dopo aver fissato il 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; 
    }; 
} 
Problemi correlati