从网页中检测我自己的Firefox扩展 [英] Detecting my own Firefox extension from a webpage

查看:166
本文介绍了从网页中检测我自己的Firefox扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个简单的方法来检测我的扩展是否安装在Firefox 3.6中。这应该是从一个网页,可能使用JavaScript。



我读了很多博客,说我应该尝试从我的扩展加载图像。由于我自己的扩展,我可以写代码,这似乎是一个不必要的黑客。



我也想过设置一个全局变量的Web文档,但我无法做到这一点。我想我能写:



top.window.content.document.hasMyPlugin =真



但是这似乎不起作用(hasMyPlugin没有定义)。我只在访问我的域时添加了这个变量(我已经添加了一个WebProgressListener并检查了主机属性),所以全局的命名空间污染应该不成问题。




$ b

UPDATE

我试图访问这个变量的方法很简单, code>如果(hasMyPlugin)或如果(document.hasMyPlugin) ...也许我访问了错误的方式?

解决方案

一个简单的方法是让您的扩展对用户定义的事件做出反应。您的网页将在适当的事件目标上分派事件(如果没有更好的事情,您可以使用该文档),然后您的扩展的事件侦听器可以验证网页地址并执行操作。事件监听器至少可以调用事件的preventDefault()方法;网页可以调用getPreventDefault()来查看你的扩展是否存在。


I am trying to find an easy way to detect if my extension is installed in Firefox 3.6. This should be done from a webpage, probably using 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. 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). 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.

Any ideas?

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?

解决方案

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; the web page could then call getPreventDefault() to see whether your extension is present.

这篇关于从网页中检测我自己的Firefox扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆