title: Firefox extension: Add javascript to webpage
body: <p>I'm working on a FireFox extension that listens to <code>onStateChange</code>. When the current document has been loaded it should insert a script to the page and it should be able to call the script on a button event.</p>
  
  <p>Now I am able to add a button to all webpages by using:</p>
  
  <pre><code>nsCOMPtr&lt;nsIDOMElement&gt; NewInputElementTest;
  rv = htmlDoc-&gt;CreateElement(NS_LITERAL_STRING("input"),getter_AddRefs(NewInputElementTest));
  
  rv = NewInputElementTest-&gt;SetAttribute(NS_LITERAL_STRING("type"),NS_LITERAL_STRING("button"));
  
  rv = NewInputElementTest-&gt;SetAttribute(NS_LITERAL_STRING("value"),NS_LITERAL_STRING("hummer"));
  
  rv = body-&gt;AppendChild(NewInputElementTest,getter_AddRefs(AddedNewInputElement2));
  
  The button is displayed correctly.
  
  
  I wish to use the same procedure to add a SCRIPT to the page, like so:
  
  rv = htmlDoc-&gt;CreateElement(NS_LITERAL_STRING("script"),getter_AddRefs(NewInputElement));
  rv = NewInputElement-&gt;SetAttribute(NS_LITERAL_STRING("type"),NS_LITERAL_STRING("text/javascript"));
  rv = NewInputElement-&gt;SetAttribute(NS_LITERAL_STRING("text"),NS_LITERAL_STRING("alert('hello world!')"));
  rv = body-&gt;AppendChild(NewInputElement,getter_AddRefs(AddedNewInputElement));
  </code></pre>
  
  <p>All functions return success, but no script is added to the page. No alert is displayed, and if i insert a function and call it from the button.onclick then the FireFox log displayes that the function is not available.</p>
  
  <p>If I use the exact same procedure from a javascript inside the html page, then it works find and the alert pops up.</p>
  
  <p>Do I need to do anything to enable the script from my extension or why is the script not available from the button or anywhere else?</p>