1

I am trying to insert a plugin I created into a page using a content script in a Google Chrome extension. According to the documentation: "If your plugin is "public", you can even use a content script to programmatically insert your plugin into a web page." http://code.google.com/chrome/extensions/npapi.html

Unfortunately the examples they give do not inject a plugin programmatically. In the 'background.html' file I embed the plugin using:

and then I can get the plugin by simply calling: document.getElementById('myPlugin')

How do I do this in a javascript content script?

1 Answer 1

1

They mean you need to use the content script to insert the embed tag and information: (psuedo code)

function addIt(){
  myEmbed = document.createElement('embed');
  myEmbed.attributes(add your attributes so easy with jquery);
  document.getElementByTagName('head')[0].append('myEmbed');
}
Sign up to request clarification or add additional context in comments.

4 Comments

Here are a couple of links that might be helpful to you while working with npapi: groups.google.com/a/chromium.org/group/chromium-extensions/… ....and.... developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
Hmm when I try to call the plugin method I get "Uncaught error: Error calling method on NPObject" any ideas?
function addIt(){ myEmbed = document.createElement('embed'); myEmbed.setAttribute("type", "application/x-myPlugin"); myEmbed.setAttribute("id", "myPlugin"); document.getElementById("LikePluginPagelet").appendChild(myEmbed); } //In a separate function var plugin = document.getElementById('myPlugin'); plugin().connectMe(false, false, "Hello", "Parameter", ""); Jeez I'm not sure how to format this its not formatting it properly.
O wait I actually got it. The last line should just be: plugin.connectMe(...). Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.