esnadr
esnadr

Reputation: 445

Get the source url of link by custom firefox MenuItem

I have tried to:

that is my code , which fail to show menu item at all :

 var contextMenu = require("sdk/context-menu");
 var menuItem = contextMenu.Item({
                              label         : "Show the url",
                              context       : contextMenu.SelectorContext("a[href]"), 
                              contentScript : 'self.on("click", function (node , data) {' + '  self.postMessage(node.src);' +'});',
                              onMessage: function (url) { console.log(url);}
                             });

I have got the following log :

console.log: rd-addon: null

Upvotes: 1

Views: 369

Answers (3)

tortway
tortway

Reputation: 21

Good for me:

context: [cm.URLContext("*"), cm.SelectorContext("a[href], img")],
contentScript: 'self.on("click", function (node, data) {' +
    '  self.postMessage(node.href||node.src);' +
    '});',

Upvotes: 2

Noitidart
Noitidart

Reputation: 37228

change:

context       : contextMenu.SelectorContext("a[href]"), 

to

context: contextMenu.URLContext("*"),

Upvotes: 2

Noitidart
Noitidart

Reputation: 37228

did you try just [href]? if not then in the contentScript change it to this:

contentScript : 'self.on("click", function (node , data) { if (node.nodeName != "A") { return false } ' + ' self.postMessage(node.src);' +'});',

try that if it doesnt work let me know. the solution i prefer is non-sdk and i can share that with you then

Upvotes: 0

Related Questions