DReJ
DReJ

Reputation: 1974

Detect version of the plugin in Chrome browser

I have NPAPI plugin and I want to detect its version before I embed it into web page. If version is not the latest one I want to show some message that asks users to update the plugin.

Now it's implemented in the following way

if (navigator.mimeTypes && navigator.mimeTypes["application/myplugin"]) {
{
    // some code here

    if(navigator.plugins["myplugin"] && navigator.plugins["myplugin"].version >= latest_version) {
        // we have the latest version (embed the plugin into web page)
        document.write ("<object id='plugin'><embed ....></object>");
    } else {
        document.write ("Show message here");
    }

    // some code
}

The problem is that navigator.plugins["myplugin"].version works fine in Firefox but not in Chrome. Chrome doesn't expose version property. I can add my own property in NPAPI code, but I don't see the way I can use it before embedding the plugin into page.

Is there any workaround?

Thanks in advance, Andrew

Upvotes: 1

Views: 3267

Answers (3)

Gaurav Raj
Gaurav Raj

Reputation: 708

You can create a JSAPI property of your plugin containing the version. This property returns the plugin's version when called from javascript. So when you try to insert/embed the plugin in the page, you can check through javascript to make the appropriate calls.

Upvotes: 0

taxilian
taxilian

Reputation: 14324

I actually put the version number in the filename, rather than even the name or description. The reason for this is that if there are multiple plugins with the same name, description, and mimetypes Firefox will generally use the latest version. Older versions of firefox have been inconsistent in how they handle this, so I even usually put the np???_version.dll file in a version-specific subdirectory.

It is a little bit of a pain, but it works consistently the same way in every NPAPI browser.

Upvotes: 1

Stever B
Stever B

Reputation: 4117

I see a lot of plugins have version information in either the name or the description. You should be able to access that information before the embed.

Upvotes: 1

Related Questions