Search code examples
javascriptfirefox-addon-sdk

Changing the contentURL of a panel based on the actions on the current page rendered on panel


I am using Erik Vold's toolbar button. I have a panel anchored to it. When one of the links is clicked on the html static page rendered in the panel, I need to display something else in the same panel.

I am trying to use port API for message passing between addon-code and the html static page. On listening a certain event, I want to change the contentURL field of the panel:

var myScript = "window.addEventListener('click', function(event) {" +
           "  var t = event.target;" +
           "  if (t.nodeName == 'A')" +
           "    self.port.emit('click-link', t.id);" +
           "}, false);"

var mainPanel = require("panel").Panel({
  width: 200,
  height: 200,
  contentURL: require("self").data.url("appList.html"),
  contentScript: myScript
});

mainPanel.port.on("click-link", function(appName) {
  if(appName=='app1'){
  //mainPanel.resize(700,500);  --works
    mainPanel.contentURL="http://www.some-server/app1.html";  --fails
  }
  if(appName=='app2')
    ...
});

mainPanel.resize() works fine for resizing the panel. Is there a similar way to change contentURL for a Panel?


Solution

  • That code should work, you found a bug in the panel module. yay!

    I filed bug 795490 for you and there's a pull request with a fix that might take a little time to land but a fix should be coming.