检查用户是否安装了Chrome扩展程序 [英] Check whether user has a Chrome extension installed
问题描述
我正在构建Chrome扩展程序,整个过程按照我希望的方式进行,我需要一个外部JavaScript脚本才能检测用户是否安装了我的扩展程序。例如:一位用户安装我的插件,然后用我的脚本进入一个网站。该网站检测到我的扩展程序已安装并相应地更新了页面。
这可能吗?
我确信有一个直接的方法(直接调用你的扩展的函数,或者通过使用JS类的扩展),而是一个间接的方法(直到更好的东西出现):
您的Chrome扩展程序是否在您的网页上查找特定的DIV或其他元素,并使用特定的ID。
例如, :
< div id =ExtensionCheck_JamesEggersAwesomeExtension>< / div>
执行 getElementById
并设置 innerHTML
添加到您的扩展的版本号。然后,您可以阅读该客户端的内容。
虽然如此,您应该使用直接方法。
编辑:找到直接方法!!
使用连接这里找到的方法: https://developer.chrome.com/extensions/extension#global-events
未经测试,但你应该可以做...
var myPort = chrome.extension.connect('yourextensionid_qwerqweroijwefoijwef',some_object_to_send_on_connect);
I am in the process of building a Chrome extension, and for the whole thing to work the way I would like it to, I need an external JavaScript script to be able to detect if a user has my extension installed.
For example: A user installs my plugin, then goes to a website with my script on it. The website detects that my extension is installed and updates the page accordingly.
Is this possible?
I am sure there is a direct way (calling functions on your extension directly, or by using the JS classes for extensions), but an indirect method (until something better comes along):
Have your Chrome extension look for a specific DIV or other element on your page, with a very specific ID.
For example:
<div id="ExtensionCheck_JamesEggersAwesomeExtension"></div>
Do a getElementById
and set the innerHTML
to the version number of your extension or something. You can then read the contents of that client-side.
Again though, you should use a direct method if there is one available.
EDIT: Direct method found!!
Use the connection methods found here: https://developer.chrome.com/extensions/extension#global-events
Untested, but you should be able to do...
var myPort=chrome.extension.connect('yourextensionid_qwerqweroijwefoijwef', some_object_to_send_on_connect);
这篇关于检查用户是否安装了Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!