开发者

Detecting my own Firefox extension from a webpage

开发者 https://www.devze.com 2023-02-12 03:46 出处:网络
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 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 no开发者_StackOverflow中文版t 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.


See here: Allow content documents (web pages) to detect my Firefox addon

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号