Question

I recently started learning firefox addon development using Addon-SDK.

I created a simple addon which displays the current webpages URL, but I'm not getting the results.

Here's my main.js file

var widgets = require("sdk/widget");
var tabs = require("sdk/tabs");
var data = require("sdk/self").data;

var showipWidget = widgets.Widget({
    id : "show-ip",
    label : "Display IP Address of current Page",
    contentURL : data.url("lens_icon.png"),
    contentScriptURL : data.url("click_handler.js"),

    /*onClick : function() {
        var curtab = tabs.activeTab;
        console.log(curtab.url+" is Opened in Browser.");
    }*/

});

And The ContentScript click_handler.js

document.write(document.URL);

However when I use onClick event (commented code above) the URL is logged in console.
I think I'm accessing document object in wrong way. Can anyone show me how to do it right way.

Was it helpful?

Solution 2

Figured out my problem. It was a silly mistake, I used contentScriptURL which is wrong. The correct term is contentScriptFile. I mixed content and contentURL with contentScript.

Reference from firefox: http://tinypic.com/r/34447mc/8

OTHER TIPS

That's weird that should work.

But try putting this in your content script:

var check = self.port.on("check", function() {
    var location = window.location.href;
alert(location + " is opened in browser");
}

then emit that check function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top