简体   繁体   English

从网页中检测我自己的Firefox扩展程序

[英]Detecting my own Firefox extension from a webpage

I am trying to find an easy way to detect if my extension is installed in Firefox 3.6. 我试图找到一种简单的方法来检测我的扩展是否安装在Firefox 3.6中。 This should be done from a webpage, probably using javascript. 这应该从网页上完成,可能使用javascript。

I've read a lot of blogs that says that I should try loading an image from my extension. 我已经阅读了很多博客,说我应该尝试从我的扩展程序中加载图像。 Since I own the extension, and I can write the code, that seems like an unnecessary hack. 由于我拥有扩展,我可以编写代码,这似乎是一个不必要的黑客。

I've also thought about setting a global variable to the web document, but I havn't been able to achieve this. 我还考虑过为web文档设置一个全局变量,但是我无法实现这一点。 I thought I would be able to write: 我以为我能写:

top.window.content.document.hasMyPlugin = true

but this is doesn't seem to work (hasMyPlugin is not defined). 但这似乎不起作用(hasMyPlugin未定义)。 I only add this variable when visiting my domain (I have added a WebProgressListener and check the host property), so global namespace pollution shouldn't be a problem. 我只访问我的域时添加了这个变量(我添加了一个WebProgressListener并检查了主机属性),因此全局命名空间污染应该不是问题。

Any ideas? 有任何想法吗?

UPDATE UPDATE

The way I try to access the variable is simply if(hasMyPlugin) or if(document.hasMyPlugin) ... Perhaps I'm accessing it the wrong way? 我尝试访问变量的方式只是if(hasMyPlugin)if(document.hasMyPlugin) ...也许我以错误的方式访问它?

One simple way is to make your extension react to a user-defined event. 一种简单的方法是使扩展对用户定义的事件做出反应。 Your web page dispatches the event on an appropriate event target (you can use the document if you have nothing better) and then your extension's event listener can verify the web page address and perform an action. 您的网页会在适当的事件目标上调度事件(如果您没有更好的内容,则可以使用该文档),然后您的扩展程序的事件侦听器可以验证网页地址并执行操作。 At the very minimum your event listener could call preventDefault() on the event; 您的事件监听器至少可以在事件上调用preventDefault(); the web page could then call getPreventDefault() to see whether your extension is present. 然后,网页可以调用getPreventDefault()来查看您的扩展是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的Firefox扩展程序不使用从Firefox 4的网页中提取的jQuery 1.4.2对象添加事件处理程序 - Why does my Firefox extension not add event handlers using jQuery 1.4.2 object pulled from webpage in Firefox 4 从Firefox中的网页访问扩展程序的功能 - Access extension's functions from webpage in Firefox Firefox扩展:从网页js调用功能 - Firefox extension: invoking function from webpage js 从网页Firefox扩展中复制数据 - Copy Data from webpage Firefox extension 网页初始加载时从扩展到网页的数据 - Firefox - Data from Extension to Webpage for Initial Load of the webpage - Firefox 如何捕获源自我自己的Firefox Web扩展的流量 - How can I capture traffic originating from my own Firefox Web Extension 检测用户从mozilla firefox扩展中单击的元素 - Detecting element on which the user has clicked from mozilla firefox extension 如何从Firefox扩展名执行网页名称空间(范围)中的javascript代码? - How to execute javascript code in the namespace (scope) of the webpage, from a firefox extension? 如何从网页调用Firefox扩展中定义的JS函数? - How to call JS function defined in Firefox extension from webpage? 从网页调用firefox扩展main.js中的函数 - call to function in firefox extension main.js from webpage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM