javascript - Google map 仅在 IE7 中无法加载 : 'Unexpected call to method or property access'

标签 javascript google-maps internet-explorer-7 google-maps-api-3

我有一个 map ,当用户单击按钮时,它会初始化谷歌地图。这会触发运行此方法的事件:

$self.maps = {
    loadMap : function(){
        var canvasDom = "map";
        var latlng = new google.maps.LatLng(40.7608, -111.8910);
        var myOptions = {
            zoom: 12,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        $self.vars.maps.map = new google.maps.Map(document.getElementById(canvasDom), myOptions);
    },
//other methods in the object for handling other maps stuff...
};

当调用最后一行来创建新 map 时,出现以下错误: “SCRIPT65535:意外调用方法或属性访问。” main.js,第 31 行字符 347

它似乎中断的代码行是:

a[Va](b);

所有这些都适用于 Firefox、Chrome、IE8 和 IE9,以及我尝试过的所有浏览器,除了 IE7(使用 IE9 的兼容模式)。

更新:我已经设置了 JSFiddle for this ,以相同的方式初始化 map ,只是由于某种原因它不会重现我在应用程序中遇到的 IE7 错误。我不太确定这说明了这个问题。

最佳答案

经过几个小时痛苦地注释掉寻找冲突的脚本后,我开始手动粘贴在创建 map 时正在运行的代码块。最终,我将其归咎于罪魁祸首。

看看这个:

//set that the map is open, and
//should remain so if the user searches again
$('form').append('<input type="hidden" name="map" value="true">');

$('#search-list-map')
    .removeClass('listview')
    .addClass('mapview');

//show map, hide list
$('#map').removeClass('hide');
$('#listResults').addClass('hide');

//initialize the map
$self.maps.loadMap();

loadMap() 是我在上面的问题中引用的方法。 注意到我附加到表单中的输入字段了吗? 事实证明,如果有一个元素的 name 与 map div 的 id 相同>,并且该元素出现在 DOM 中的 map div 之前,将会抛出错误。据我所知,这种情况只会出现在IE7中(可能是IE6,我无法测试)。

我已经在 J​​SFiddle 上重现了该错误,here 。在IE7下运行它,你就会成功。

关于javascript - Google map 仅在 IE7 中无法加载 : 'Unexpected call to method or property access' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568815/

相关文章:

css - IE7 定位问题(顶栏的绝对和固定定位留在原地)

javascript - 使用 Web api 和 Angular JS 将数据下载为 Excel 文件

javascript - JS OOP 初学者培训错误

javascript - 获取表单值并将其传递给提交时的 Bootstrap 模式

javascript - 在 IE 中跨不同窗口使用 Javascript 对象

google-maps - 谷歌地图静态API中的自定义图标 anchor

html - IE7截断图像

android - 不仅仅是标记自定义信息窗口中的标题和 fragment

javascript - Instagram 图片到您周围 1 公里半径内的 Google map

css - 旋转 div 内容的 IE7/8 css 问题