Window.open,while循环和window.close

时间:2014-08-13 17:17:43

标签: javascript file firefox window xul

我的firefox扩展程序有问题。我正在做一个下载网页的扩展,将其保存为PDF,然后将其上传到服务器中。问题出在这里:

var myWindow = window.open('chrome://xulschoolhello/content/progressmeter.xul',
'',' top=100, left=100, height=20, width=130');                            
while(file.exists() == false) {         
}     
myWindow.close();  

要上传文件,我需要该文件存在,所以我必须等到它存在。所以,我制作了一个进度表,以显示它正在进行中,但extesion必须检查文件是否存在。 while循环不能为空,我试图在没有firefox崩溃的情况下保持它的优势。任何的想法?非常感谢你。

2 个答案:

答案 0 :(得分:0)

只需用文件检查替换下面的a = 10.

function test() {
    var a = 0;
    function rep() {
        setTimeout(function() {
            a++;
            if (a < 10) {
                rep();
                console.log("a" + a);
            } else {
                console.log("ending a" + a);
            }
        },300);
    }

    rep();
}

试验();

答案 1 :(得分:0)

我解决了我的问题。这是代码:

var myInterval = setInterval((function(){
    if (file.exists()) {
        clearInterval(myInterval);
        continues();
    }
}),1000);

function continues(){}

每隔一秒,它会检查文件是否退出,而不是while循环。