Detecting my own Firefox extension from a webpage

I am trying to find an easy way to determine if my extension is installed in Firefox 3.6. This should be done from a web page, possibly using javascript.

I read a lot of blogs that say I should try downloading an image from my extension. Since I have an extension, and I can write code that seems like an unnecessary hack.

I also thought about setting a global variable in a web document, but I couldn’t. I thought I could write:

top.window.content.document.hasMyPlugin = true

but this does not seem to work (hasMyPlugin is undefined). I only add this variable when visiting my domain (I added the WebProgressListener and check the host property), so global namespace pollution should not be a problem.

Any ideas?

UPDATE

The way I'm trying to access a variable is simple if(hasMyPlugin)or if(document.hasMyPlugin)... Perhaps I am accessing it incorrectly?

+5
source share
2 answers

One easy way is to make your extension respond to a user-defined event. Your webpage sends an event to the appropriate target (you can use the document if you have nothing better), and then your extension event listener can check the address of the webpage and perform the action. At a minimum, your event listener might call preventDefault () on the event; the webpage can then call getPreventDefault () to find out if your extension is present.

+4
source
0

All Articles