Accessing the DOM in a Firefox for Android add-on -
this sounds simple question, i've been going through mdn documentation of "firefox android" , can't seem figure out.
i'm trying build simple "firefox android" add-on, inserts script tag visited pages. i've tried following code (leaving out template boilerplate code):
function loadintowindow(window) { if (!window) return; menuid = window.nativewindow.menu.add("insert", null, function() { insertscript(window); }); } function insertscript(window) { // none of these properties exist: window.document.body.innerhtml, window.body.innerhtml // window.document.body.innerhtml = "<h1>this page has been eaten</h1>"; // var contentscriptstring = 'document.body.innerhtml = "<h1>this page has been eaten</h1>";' // throws error "referenceerror: require not defined" // var tabs = require("sdk/tabs"); // tabs.activetab.attach({ // contentscript: contentscriptstring // }); // throws error "typeerror: attach not function" // window.browserapp.selectedtab.attach({ // contentscript: contentscriptstring // }); } function unloadfromwindow(window) { if (!window) return; window.nativewindow.menu.remove(menuid); }
the loadintowindow function being correctly called, since "insert" option added menu option, , option in turn correctly calls insertscript option when tapped.
however, i'm @ loss on how access window's dom in order insert script. i've tried options mentioned on page content scripts , browserapp property..
thanks,
william
looks can answer own question. after looking through browser.js, found following code works access current page's dom:
var contentwindow = window.browserapp.selectedbrowser.contentwindow; var document = contentwindow.document; document.body.innerhtml = "<h1>this page has been eaten</h1>";
Comments
Post a Comment