0

I have browser plugin for Safari/Firefox on Mac.When user launch webpage it will ask user to download the plugin.Ideally it should refresh the page automatically when download is done and make use of plugin.

The code is able to detect the plugin but when I call method in plugin it is throwing exception. If I manually refresh the page and call the plugin method I am able to do it.

InitPlugin()
{
var IsPluginInstalled;
var plugin = navigator.plugins["My Plug-In"]; // success
var engine;
if (plugin)
{
     engine = plugin.getElementById("MyPlugin");
     var version = engine.getAttributeByKey("my_plugin_version"); // crashing here.
    IsPluginInstalled  = true;                             

}
}
RefreshPlugin()
{
       navigator.plugins.refresh();
       if (!InitPlugin())
       {
          setInterval(InitPlugin,3000);
       }

}

after install page should refresh automatically This is code is working fine if refresh the page manually.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Vikram Ranabhatt
  • 7,268
  • 15
  • 70
  • 133

1 Answers1

0

I don't see where this refreshs the page. What should work though is re-instantiating the plugin (e.g. by switching it to display:none and back).

This also looks like you could be accessing the plugin too soon - the plugin might not have finished instantiating yet.

After finding it listed in navigator.plugins and (re-)instantiating you could:

  • periodically try accessing it until it works or
  • (better) have your plugin call into the page when it finished loading

In both cases you'll want to time out after a "reasonable" time and conclude that either it

  • failed to load or
  • the plugin is being blocked (plugin being set to click-to-play or some extension blocked it)

... there is a best-practices article for this on MDN.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • :Is there any way to know whether Browser Plugin is loaded or not through Java script.If I know that I can reload the page – Vikram Ranabhatt Aug 08 '13 at 14:15
  • You can tell if it's loaded within a certain time frame via the approach(es) above, but you can't tell for sure why it hasn't loaded within it (plugin failed to instantiate, is click-to-play, ...). – Georg Fritzsche Aug 08 '13 at 18:17