[英]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.