I am trying to convert a Greasemonky script to an extension for Firefox, and I am trying to have my extension automatically attach a simple script to any web page when opening a new tab. I am converting a script from Greasemonkey because I would like to use the advanced settings and menu options.
I access the tab using this:
var container = gBrowser.tabContainer; container.addEventListener("TabOpen", tabAdded, false); function tabAdded(event) { var newtabwindow = event.target.____
and my goal is to add the script to the document in a new tab after loading using this function:
function scriptrunner(targetwindow) { var myScript = targetwindow.content.document.createElement('script'); myScript.type = 'text/javascript'; myScript.setAttribute('src','chrome://addonname/content/addonscript.js'); targetwindow.content.document.getElementsByTagName('head')[0].appendChild(myScript); }
This function is great for attaching a script to the current page when connecting to a toolbar button using oncommand = "scriptrunner (window)", but I donβt know how to access the window in a newly opened tab, or if I have to cut the window from equations and access the document in another way.
source share