gpt4 book ai didi

javascript - 刷新附加 SDK 中的 contenturl

转载 作者:行者123 更新时间:2023-12-03 11:15:56 26 4
gpt4 key购买 nike

当我单击小部件图标时,如何使用 contenturl 刷新面板?我的代码很简单:

    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
});
};

最佳答案

在小部件点击时更改面板的contentURL,如下所示:

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

记住以下几点

Widget docs :

The widget API is deprecated from Firefox 29 onwards. Please see the ui module for replacements. In particular, for a simple button, try the action button or toggle button APIs.

Panel docs :

You can attach a panel to a toggle button by passing the button itself as the position option to the panel's show() method or to its constructor:

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});
}

关于javascript - 刷新附加 SDK 中的 contenturl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27347860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com