2013-12-20 34 views
1

在我的一個Firefox插件中,我需要使用setTimeout函數定時器。我寫了下面的代碼:Firefox的計時器插件

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

你能否告訴'player.content =「1024x980」;'正在運行? –

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