javascript - google.load 上 IE8 中的神秘 'object doesnt support this method' 错误

标签 javascript internet-explorer google-api

我在我的本地搜索应用程序中使用谷歌搜索 JSAPI。在除 IE 8 之外的所有浏览器中一切正常。问题是在我的 jquery 基础对象和 google 对象被 drreferenced 的特定代码行之后。

这是一个直接的代码。我能够使用 this jsfiddle 重现问题.

html代码是

<html>
    <head>
        <title>Test Map</title>
        <script src="http://www.google.com/jsapi?" type="text/javascript"></script>

    </head>
    <body>
        <div id="map_canvas"></div>
    </body>
</html>

和JS

$(function() {
    alert(1);
    google.load('search',1);
    alert($);

    google.setOnLoadCallback(function() {       
        alert(2);
    });
});

google.load('search',1) 行之后我得到了以下错误

错误:对象不支持此属性或方法

$google

这完全是一场噩梦。我为此奋斗了几个小时而没有运气。这里的 IE 专家有什么想法吗?

最佳答案

将您的 jsFiddle 更改为“No wrap (body)”并像这样修改您的函数...

//$(function() {
    //alert(1);
    google.load('search',1);
    alert($);

    google.setOnLoadCallback(function() {       
        alert(2);
    });
//});

这里问的问题几乎相同:Google is not defined using Google Visualization API; possibly jQuery's fault

关于javascript - google.load 上 IE8 中的神秘 'object doesnt support this method' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9748331/

相关文章:

javascript - Windows Phone 8.1 本地存储无法工作

internet-explorer - Web 组件、HTML 导入 polyfill 在 Firefox、IE 中不起作用

javascript - 为什么IE11在使用window.onbeforeunload时会报错?

laravel - 使用 laravel 分析的用户事件请求

api - 如何将 IPv6 地址添加到 Google API 凭据?

javascript - 将 Javascript 中的值返回到 C# HTML 文件

javascript - jquery改变图像

javascript - 是否可以在 IE8+ 的浏览器窗口中打开 .js 文件(像 Firefox 一样)

google-api - 尝试创建新的 Google API 项目时出现 FAILED_PRECONDITION

javascript - 检索 Updatepanel 是否已进行回发