2012-03-17 36 views

回答

2

恐怕你必須創建一個內容腳本,註冊時要關閉面板被稱爲監聽器。內容腳本應通過self.port.emit('your-event-name')與插件通信,且插件代碼應通過panel.port.on('your-event-name')監聽通知關閉面板:

 var kipptPanel = require("panel").Panel({ 
      width:400, 
      height:245, 
      // The contentURL should do this to close the panel: 
      // <button id="close-button">self.port.emit('close', null)</button> 
      contentURL : "http://localhost:8000/test-panel.html", 
      contentScript: "document.getElementById('close-button').addEventListener('click', function() {" + 
          " console.log('zz');self.port.emit('close', null);" + 
          "});" 
     }); 
     kipptPanel.port.on("close", function (text) { 
      console.log(text); 
      kipptPanel.destroy(); 
     }); 
     kipptPanel.show(); 

這裏有一個modified version of your code in the add-on builder

這在SDK's panel documentation中有描述。

我意識到它太複雜了,你可能想問在噴氣揹包組中是否使window.close()關閉了面板。

+0

我不確定在關閉標籤時關閉面板會有什麼意義作爲一般功能。該面板是Chrome瀏覽器的一部分,*不*附加到任何給定的選項卡。 – canuckistani 2012-03-18 02:26:57

+0

@canuckistani:我在問題中解析該句子的方式是:當在面板中打開的文檔中調用'window.close()'時,面板將關閉(在Chrome中)。對於我,這說得通。 – Nickolay 2012-03-18 10:41:29

+0

太棒了,這是我一直在尋找的東西。非常感謝! – jorilallo 2012-03-18 14:49:31