“google is undefined”

試著忘記壹切 提交于 2019-12-13 05:49:02

问题


I'm using Gears which works well in FF3 and Safari; IE6/7 both report a "google is undefined" error on page load, appearing in gears_init.js. A quick web search showed that Javascripts by Google are actually causing problems in IE7. Does anybody have an idea for a workaround?


回答1:


This is probably because IE6/7 don't have gears installed. That means the google related code won't be available.

You probably just want to do something like:

if ( !window.google ) {
    alert("please install google gears");
}
else {
    // gears is available
}

Though in reality you'd want to do something a bit nicer than showing an alert to tell the user to download gears.




回答2:


I am using IE8 and I am writing following code, that works fine in Mozilla Firefox but can't working in IE8

if (!window.google || !google.gears) {
        if (confirm("This application requires Gears to be installed. Install now?")) {
            location.href = "http://code.google.com/apis/gears/install.html"
            return;
        } else {
            addStatus('Gears is not installed', 'error');
            return;
        }
}

The first condition !window.google is working fine but second condition !google.gears didn't work for IE8, said google is undefined



来源:https://stackoverflow.com/questions/657555/google-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!