javascript - 为什么我的 javascript 循环不起作用并使我的 chrome 浏览器崩溃?
问题描述
更新
我为我的浏览器控制台制作了这个 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 = true; 在你的函数内部是第二个分配的变量,它只在函数内部可用。
推荐阅读
- qt - QSystemTrayIcon 不返回任何几何信息
- python - 使用 Camelot 从此 PDF 中提取数据时未找到表并合并列文本
- angular - Angular 组件命名限制 - “选择器 [您的组件名称] 无效”
- mainframe - ONCODE=451 提出了存储条件
- cmd - 为什么 SHIFT 不改变值?
- c# - xml序列化时排除根节点
- uwp - IoT Core UWP 应用程序在写入以停止 UHF 阅读器后挂在 DataReader.LoadAsync 上
- python - discord bot 删除消息,直到说出命令时的实际时钟上的特定时间
- azure - 将 Azure 流量管理器与应用服务 (HTTPS) 结合使用
- java - 为什么我会收到 NoSuchElementException?