Javascript:每 10 秒从 URL 数组中更改 location.href ?

标签 javascript timeout href settimeout location-href

我通过从与某个类名匹配的元素数组中获取 href 属性来获取 URL 列表。直到这里一切都很顺利。然后,我尝试通过迭代 URL 数组,每 10 秒更改一次页面的 location.href。但出于某种原因,什么也没有发生。我做错了什么?

var buttonsElements = document.getElementsByClassName("elementor-button-link elementor-button");
console.log(buttonsElements.length); 
for(i=0;i<buttonsElements.length;i++) {
    console.log(buttonsElements[i].href); 
    //everything works just fine until here

 setTimeout(function(){
        window.location.href = buttonsElements[i].href;
    },10000);
}

最佳答案

我不太清楚你想做什么。请注意,一旦您分配了 href,浏览器就会将您带到另一个页面,并且脚本将被中断。

关于Javascript:每 10 秒从 URL 数组中更改 location.href ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59824161/

相关文章:

javascript - 如何使用纯javascript从 Sprite 表中提取 Sprite

javascript - 将参数传递到 FOR 循环中

python - 如何在多处理中结合 TimeoutError 和 tq​​dm 进度条?

javascript - 如果超时后重复调用该方法,如何在sinon中进行测试

javascript - 有没有更好的方法来防止单击 href 时整个页面滚动?

javascript - 允许 mailto href 链接中包含 '&' 字符

javascript - 使用 curl -X PUT 测试 REST 路由,返回 404

javascript - 为什么 ng-selected 调用函数 n 次

javascript - 多次调用同一函数时跟踪每个 $timeout

php - Href V/s 表格提交