So using the example in the SDK docs (below) doesn’t work in the sense that it doesn’t prevent the URL in the href from loading in the panel, and it doesn’t console log anything. I’m not sure as to why it’s not working the way it’s specified in the SDK docs, unless it’s outdated?
var myScript = "window.addEventListener('click', function(event) {" +
" var t = event.target;" +
" if (t.nodeName == 'A')" +
" self.port.emit('click-link', t.toString());" +
"}, false);"
var panel = require("sdk/panel").Panel({
contentURL: "http://www.bbc.co.uk/mobile/index.html",
contentScript: myScript
});
panel.port.on("click-link", function(url) {
console.log(url);
});
panel.show();
Stuck as in the code isn’t working thus leading me to not understand, I read the docs and understood it until I went to apply it. Then it doesn’t work. I know that port communicates the content scripts with the main add-on JavaScript and I need it to. I don’t know the where the event/core module would come in if it allows you to broad cast and listen for events, when “port” from what I read does that. I’ve tried including the event/core module with what I’m trying to do and without it, but I still can’t seem to get it to emit events. As I have said, I even copied the examples from the docs to test it after it didn’t work for me and it still doesn’t work testing it with the example in the docs.