0

我想检测是否安装了 chrome 扩展程序。

例如下面的代码来检测 Measureit。它添加了一个 id 为 shadowMeasureIt 的 div。

<head>
    <meta charset="utf-8">
<link rel="chrome-webstore-item"
    href="https://chrome.google.com/webstore/detail/aonjhmdcgbgikgjapjckfkefpphjpgma">

    <body>
<button onclick="chrome.webstore.install()" id="install-button">Add to Chrome</button>    
</body>
<script>

        if (document.getElementById('shadowMeasureIt')) {
  //document.getElementById('install-button').style.display = 'none';
  alert ("yes");
}
</script>

它不起作用,但是当我在控制台中运行脚本时,它会提示“是”。

我怎样才能让它工作。

提前致谢。

4

2 回答 2

0

您应该尝试使用这种方法:

chrome.management.get(string id [, function callback])

示例(未经测试):

var myExtension = chrome.management.get( "my_extention_id" );
if (myExtension.enabled)
{
// installed
}
else { ... }

来源:http: //developer.chrome.com/extensions/management.html#method-get

于 2012-10-06T12:51:34.700 回答
0
chrome.management.get("extension_id",function (extensionInfo) {
    console.log(extensionInfo);
});

清单中必须有 "permissions": [ "management" ]。

extension_id 将是您想要查找的扩展名。

于 2020-12-07T08:53:26.403 回答