Javascript:从URL数组每10秒更改一次location.href吗? [英] Javascript: changing location.href every 10 seconds from an array of URLs?

查看:100
本文介绍了Javascript:从URL数组每10秒更改一次location.href吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过gettig从href属性中获取URL列表,该href属性是从与某个类名匹配的元素数组中获得的.一切都很好,直到这里.然后,我尝试通过遍历URL数组,每10秒更改一次页面的location.href.由于某种原因,什么也没发生.我在做什么错了?

I am getting a list of URLs by gettig the href attribute from an array of elements that match a certain class name. Everything works great until here. Then I am trying to change the location.href of the page, every 10 seconds, by iterating on the array of URLs. For some reason, nothing happens though. What am I doing wrong?

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,浏览器就会带您到另一个页面,脚本将被中断.

Isn't really clear to me what you're trying to do. Note, once you assign the href the browser will bring you to another page and the script will be interrupted.

这篇关于Javascript:从URL数组每10秒更改一次location.href吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆