Click here to Skip to main content
15,885,216 members
Articles / Web Development / HTML

Detecting a Firefox Extension Using JavaScript

Rate me:
Please Sign up or sign in to vote.
2.60/5 (4 votes)
29 Jul 2008CPOL2 min read 29.1K   9   2
The following explanation will help you understand how to detect if a Firefox extension is installed on your system. This also handles the problems you might face using Firefox 3.

Introduction

The article will be helpful for developers of Firefox extensions (add-ons). It describes how your web pages can detect if an extension is currently installed in your browser.

Background

The requirement is of a very typical distribution policy, where we deliver our extensions using the most popular pages of our website. Each of these popular pages, when visited, would detect if the extension if already installed; if so, it shouldn't make an attempt to download and install the extension again. However, if the extension is not installed, it can be downloaded and installed.

The code can further take care of settings cookies, and doing it periodically (once in a week), in case a user denies to install the extension - for whatever reason.

Using the code

I was stuck with detecting the existence of an extension (add-on) in Firefox using JavaScript. I used the following code to detect the presence of an extension:

HTML
<img src="chrome://toolbar/content/logo.png" 
 onload="var a=document.getElementById('PlugInStatus'); 
    a.innerHTML = 'You are using the plug-in';" 
    style="visibility: hidden;" />

<span id="PlugInStatus">You are not using the plug-in</span><noscript> 
      and/or you don't have JavaScript turned on</noscript>

The problems started arising with the launch of Firefox 3 RC1. The above code always failed from the HTMLs I needed to detect the plug-in. Browsing through Mozilla Dev docs, I came across the following: http://developer.mozilla.org/en/docs/Chrome_Registration#contentaccessible. However, there wasn't much available telling me what file(s) exactly I should modify.

Well, here is the answer for those who are stuck with something similar:

  1. Locate your chrome.menifest at the plug-in installation location, typically located at:
  2. C:\Documents and Settings\sauda\ApplicationData\Mozilla\Firefox\
       Profiles\j3nyyp9a.Saud\extensions\{33CC0A72-4C68-4D38-A06D-D51BA6A8A53E} 
  3. Open chrome.menifest and edit the contents as shown below:
  4. Existing code:

    content toolbar jar:chrome/toolbar.jar!/content/toolbar/ 

    Updated code:

    content toolbar jar:chrome/toolbar.jar!/content/toolbar/ 
    content toolbar jar:chrome/toolbar.jar!/content/toolbar/ contentaccessible=yes 

Both the lines are important as the first one makes it work in Firefox 2.0, since this version of Firefox doesn't understand the contentaccessible keyword. And, the second one is required for Firefox 3.0.

Kill any current instances of Firefox before you test your HTMLs/JSs.

Points of Interest

An interesting argument about the same can be found at Mozilla's Bugzilla system: https://bugzilla.mozilla.org/show_bug.cgi?id=292789.

Another interesting read with reference to "Chrome" is available at: http://cybernetnews.com/2008/06/24/myfive-firefox-3-chrome-urls/.

History

  • Draft version: 1.0 - 30/July/2008.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manfred Rudolf Bihy31-Mar-11 0:53
professionalManfred Rudolf Bihy31-Mar-11 0:53 
I'm not sure why this article was not appreciated. I liked it rather well. 5
GeneralRe: My vote of 5 Pin
saud_ad14-Jul-17 5:57
saud_ad14-Jul-17 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.