views:

158

answers:

1

I have a lightwiehgt plugin to firefox which needs to inject a script into the HTML. The code looks like this:

var head = document.getElementsByTagName("head")[0];
var newscrpt;       
newscrpt = document.createElement('script');
newscrpt.type = "text/javascript" ;
newscrpt.src = "http://blabla.com/...";
newscrpt = head.appendChild(newscrpt);

The problem is that document.getElementsByTagName("head")[0] returns 'undefined', and checking document.getElementsByTagName("head").length is 0.

It currently executes on the browser document.onLoad event but I also tried calling it from window.setTimeout to make sure it is not a problem with loading synchronization, but the same happens.

Any ideas from anyone? Thanks!

+2  A: 

I just had similar problem today, and managed to find a solution. Your post was from 1 month ago, so not sure whether you have solved your problem. Below link may answer your question: https://developer.mozilla.org/en/Working_with_windows_in_chrome_code

stevenq
Yeah, the OP needs to get a content window first.
Nickolay