Home Notes Web development Google Maps not loading in IE8 or IE7?

Google Maps not loading in IE8 or IE7? E-mail
Monday, 19 September 2011 07:08

I came across the following implementation of a Google Maps embedded map in a Rails application.  The map loaded fine in every popular browser except Internet Explorer 8 and 7.  After some time I figured out what it was:

 

Original code

this.drawMap = function() {
 
    if($('#map[data-map-js-url]').length > 0) {
 
        $.get($('#map').attr('data-map-js-url'), function(data){
 
        script = $(data).text();    //line to change
 
        eval(script);
 
        });
 
    }
 
}

 

Modified line that loads map in IE8 and IE7

script = $(data).html();

 

If I were to just guess at the cause, I would say that newer browser are more forgiving in what they let eval parse, whereas IE8 and IE7 require proper HTML.



Tags: jQuery  .html()  .text()  Internet Explorer  IE8  IE7  JavaScript  eval