2014-12-07 71 views
0

當我點擊小部件圖標時,如何使用contenturl刷新面板?我的代碼是在這裏簡單的是:刷新contenturl在附加sdk

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

exports.main = function() { 
    var panel = require("sdk/panel").Panel({ 
     width: 400, 
     height: 560, 
     contentURL: "http://sample.com/index.html",  
    }); 

    panel.on("show", function() { 
     panel.port.emit("show"); 
    }); 

    require("sdk/widget").Widget({ 
     id: "Sample", 
     label: "Sample", 
     contentURL: data.url("icon128.png"), 
     panel:panel 
    }); 
}; 

回答

1

改變面板的contentURL小窗口點擊像這樣:

require("sdk/widget").Widget({ 
    id: "Sample", 
    label: "Sample", 
    contentURL: data.url("icon128.png"), 
    panel:panel, 
    onClick: function() { 
     panel.contentURL = contentURL; 
    } 
}); 

請記住下面的

Widget docs

從Firefox 29開始不推薦使用窗口小部件API。請參閱ui模塊進行更換。特別是,對於簡單的按鈕,請嘗試使用action buttontoggle button API。

Panel docs

您可以通過本身傳遞按鈕的位置選項面板的show()方法或給它的構造面板連接到一個切換按鈕:

var { ToggleButton } = require('sdk/ui/button/toggle'); 
var panels = require("sdk/panel"); 
var self = require("sdk/self"); 

var button = ToggleButton({ 
    id: "my-button", 
    label: "my button", 
    icon: { 
    "16": "./icon-16.png", 
    "32": "./icon-32.png", 
    "64": "./icon-64.png" 
    }, 
    onChange: handleChange 
}); 

var panel = panels.Panel({ 
    contentURL: self.data.url("panel.html"), 
    onHide: handleHide 
}); 

function handleChange(state) { 
    if (state.checked) { 
    panel.show({ 
     position: button 
    }); 
    } 
} 

function handleHide() { 
    button.state('window', {checked: false}); 
}