繁体   English   中英

为什么我的 javascript 循环不起作用并使我的 chrome 浏览器崩溃?

[英]Why my javascript loop isn't working and make my chrome browser crash?

更新

我为我的浏览器控制台制作了这个 javascript 脚本并添加了一个循环:

var available = false;
while (available === false){
    setTimeout(function(){
        document.getElementById('CONTENU_WIN').contentWindow.location.reload()
        setTimeout(function(){
            var button = document.getElementById('CONTENU_WIN').contentWindow.document.getElementById('boutonSuivant');
            button.click();
            setTimeout(function(){
                // Get value of span text
                var span_Text = document.getElementById('CONTENU_WIN').contentWindow.document.getElementById("compTableau_tbody").innerText;
                console.log(span_Text)
                if (span_Text == "No available appointment") {
                  console.log("NONNNNN");
                } else {
                    // If "No available appointment." not detected, it means that turnos are available. 
                    // Make a sound
                    var typeWriter = new Audio("http://soundbible.com/mp3/School_Fire_Alarm-Cullen_Card-202875844.mp3");
                    typeWriter.play()
                    // Date & Time instance
                    var ts = new Date();
                    console.log(ts.toString());
                    setTimeout(function(){
                        console.log("WAITING FOR YOUR TO TAKE THE TURNO!!!!")
                        }, 200000);
                    available = true;
                    console.log(available);
                }
            }, 5000);
        }, 10000);
    }, 10000);
}

我的目标是执行第一个“if”语句,直到它无法执行并转到 else (var available = true;) 但是这个循环使我的浏览器崩溃。 我测试了不同的循环和不同的东西: - do / while - while false/true - for - setInterval - ...但我不明白为什么。 也许我对循环仍然不是很舒服。

有人可以帮助我吗? 谢谢!

我认为您正在重新分配变量available的范围。 var available = true; 在你的函数内部是第二个分配的变量,它只在函数内部可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM