检测Google地球安装在Internet Explorer的网页中

Mat*_*ock 3 javascript internet-explorer google-earth

是否可以在Internet Explorer的网页中检测是否使用Javascript在客户端计算机上安装了Google Earth应用程序?

此页面是Intranet上可信站点的一部分.

更新:通过创建ActiveX对象或任何IE特定的JavaScript检测它是好的.

Mik*_*keD 5

是的,这是可能的 - 在您的html页面上,您调用API的init函数

<body onload="init()">
   bla bla bla 
</body>
Run Code Online (Sandbox Code Playgroud)

在JavaScript中,为页面创建GE实例时,为调用错误的回调函数提供函数指针

function init()
{
    if (ge == null)
    {
        google.earth.createInstance("content", initCallback, failureCallback);
    }
}
Run Code Online (Sandbox Code Playgroud)

最后 - 在该函数中检查错误代码

function failureCallback(errorCode)
{
    if (errorCode == "ERR_CREATE_PLUGIN") {
        alert("Plugin not installed")
    } else {
        alert("Other failure loading the Google Earth Plugin: " + errorCode);
    }
}
Run Code Online (Sandbox Code Playgroud)

看看这个完整的工作代码.

祝你好运MikeD