How to reload widget popup using firefox addon sdk?

My addon opens a popup ( popup.html).

When the user changes the current tab to another tab, the pop-up panel hides until the user clicks on the add-ons icon. (Meanwhile, the addon is still "living" in the background).

When the popup opens a second time, I need to RELOAD its contentURL ( popup.html), but I found a way to do this.

It may look simple, but I have little experience with the Add-on SDK.

Any help would be appreciated.

This is my code:

exports.main = function() {
  data = require('self').data;
  var tabs = require("tabs");

  var popupPanel = require("panel").Panel({
    width:550,
    height:400,
    contentURL: data.url("popup.html"),  
    contentScriptFile: [data.url("popup.js")],       
    contentScript: " "+
      "self.port.on('curTabMsg', function(curTabMsg) {" +
        "main(curTabMsg['curTab']);" +
      "});"
  }); 


  require('widget').Widget({
    panel: popupPanel,
    onClick: function() {    
      popupPanel.port.emit("curTabMsg",{'curTab': tabs.activeTab.url}); 
    }
  });
};
+5
source share
3 answers

html iframe . ( -)

, , , .

lib myPanel.js

function getPanel(contentURL,contentScriptFile,contentScript){
    var popupPanel = require("panel").Panel({
          width:550,
          height:400,
          contentURL: contentURL,  
          contentScriptFile: contentScriptFile,       
          contentScript: contentScript
         }); 
    return popupPanel;   
}

exports.getPanel = getPanel;

main.js:

exports.main = function() {
    data = require('self').data;
    var myPanel=require("myPanel");
    var tabs = require("tabs");

    let myWidget = require('widget').Widget({
      id: "SomeId",
      label: "Some lable",
      contentURL: data.url("some.png"),
      onClick: function() { 
          var panel = myPanel.getPanel(data.url("popup.html"),[data.url("popup.js")],
                      "self.port.on('curTabMsg', function(curTabMsg) {" +
                            "main(curTabMsg['curTab']);" +
                        "});");        
          panel.show();
          panel.port.emit("curTabMsg",{'curTab': tabs.activeTab.url}); 
      }
    });
};
+4

contentScript pageContent, : "" - html , (css: {display: none;}), , .

: contentScript "". .

0

, , URL iFrame

<iframe id="mainFrame" name="mainFrame" src="" frameborder="0" height ="100%" width="100%"></iframe>

script iFram src html.

function reload(tabUrl)
{
    document.getElementById("mainFrame").src=tabUrl;
}


var popupPanel = require("panel").Panel({
          width:550,
          height:400,
          contentURL: data.url("container.html"),  
          contentScriptFile: [data.url("popup.js")],       
          contentScript: " "+
            "self.port.on('curTabMsg', function(curTabMsg) {" +
                "reload(curTabMsg['curTab']);" +
            "});"
         }); 
-1

All Articles