javascript - How to access div in Firefox Add-on SDK? -


i'm trying access div right-clicked , log code (from opening closing tag) add-on sdk.

var contextmenu = require("sdk/context-menu");  var menuitem = contextmenu.item({  label: "log div",  context: contextmenu.selectorcontext("div"),  contentscript: 'self.on("click", function (e) {' + // e empty                 '  if (!e) {e = window.event;}' + // window doesnt have event property                 '  console.log(e);' + // result {}                 '  var text = e.target;' +                 '  self.postmessage(text);' +                 '});',  onmessage: function (selectiontext) {       console.log(selectiontext); // null  } }); 

the first argument click callback the actual context node, not event.

to outer markup of node, can use .outerhtml

var contextmenu = require("sdk/context-menu");  var menuitem = contextmenu.item({  label: "log div",  context: contextmenu.selectorcontext("div"),  contentscript: 'self.on("click", function (node, data) {' +                 '  self.postmessage(node.outerhtml);' +                 '});',  onmessage: function (outerhtml) {       console.log(outerhtml);  } }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -