在我的一个firefox插件中,我需要使用timer的setTimeout函数。我写了以下代码:
exports.main = function() {
const widgets = require("sdk/widget");
const data = require("sdk/self").data;
const tmr = require('timers');
var player = widgets.Widget({
id: "player",
width: 72,
label: "Player",
contentURL: data.url("content.html"),
contentScriptFile: data.url("script.js")
});
player.port.on("play", function() {
player.content = "1024x980";
tmr.setTimeout(setTimer, 500);
});
function setTimer()
{
player.contentURL = data.url("content.html");
}
};
但它在500ms后没有触发setTimer函数。请帮我作为firefox插件开发的新手。
答案 0 :(得分:0)
我解决了这个问题。它只是我的代码中的两个问题。第一个是contentURL在这种情况下不起作用。第二个是定义前的调用方法。
exports.main = function() {
const widgets = require("sdk/widget");
const data = require("sdk/self").data;
const tmr = require('timers');
var player = widgets.Widget({
id: "player",
width: 72,
label: "Player",
contentURL: data.url("content.html"),
contentScriptFile: data.url("script.js")
});
function setTimer()
{
player.content = "your text here";
}
player.port.on("play", function() {
player.content = "1024x980";
tmr.setTimeout(setTimer, 500);
});
};