Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Chrome控制台窗口中使用超时在javascript中迭代多个URL_Javascript_Google Chrome Devtools_Webbrowser Control_Windows Console - Fatal编程技术网

如何在Chrome控制台窗口中使用超时在javascript中迭代多个URL

如何在Chrome控制台窗口中使用超时在javascript中迭代多个URL,javascript,google-chrome-devtools,webbrowser-control,windows-console,Javascript,Google Chrome Devtools,Webbrowser Control,Windows Console,我想在URL的末尾遍历具有不同php id号的URL,在执行其中一个URL后,我想打印一些数据,比如说Next之类,然后等待7秒钟,然后通过增加php id值来执行下一个URL 这就是我试图在Chrome控制台窗口中使用Javascript执行的全部内容。 如有任何疑问,请提前询问并感谢您的帮助 for(j=1000;j <= 1010; j++) { this.document.location = "http://website.com/page.php?id=" + j;

我想在URL的末尾遍历具有不同php id号的URL,在执行其中一个URL后,我想打印一些数据,比如说Next之类,然后等待7秒钟,然后通过增加php id值来执行下一个URL

这就是我试图在Chrome控制台窗口中使用Javascript执行的全部内容。 如有任何疑问,请提前询问并感谢您的帮助

for(j=1000;j <= 1010; j++) {
  this.document.location = "http://website.com/page.php?id=" + j;

  setTimeout(console.log('Next'), 7000);
}

你最好在一个框架内做这件事。这将遍历列表,等待解析当前url

常量URL=[ https://css-tricks.com , http://stackoverflow.com , https://scotch.io , http://ramdajs.com , https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe , https://www.w3schools.com/tags/tag_iframe.asp ] 常量iframe=document.querySelector'iframe' iframe.height=window.innerHeight 常量迭代=URL,超时=500,ii=0=>{ 返回e=>{ 如果iiiframe.src=URL[ii++],超时 } } } iframe.addEventListener'load',iterateurls,500 html,正文,iframe{margin:0;padding:0;overflow:hidden;} 常量URL=[ https://css-tricks.com , http://stackoverflow.com , https://scotch.io , http://ramdajs.com , https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe , https://www.w3schools.com/tags/tag_iframe.asp ] 常量iframe=document.querySelector'iframe' iframe.height=window.innerHeight var ii=0; const iterate=URL,超时=500=>{ 返回e=>{ 如果iiiframe.src=URL[ii++],超时 } } } iframe.addEventListener'load',iterateurls,500 html,正文,iframe{margin:0;padding:0;overflow:hidden;}
谢谢你提供的信息。。。那么,如果我打开一个新窗口并在该窗口上运行,然后关闭该窗口并再次使用新的php id打开一个新窗口。。。这行吗?上面的函数将首先检查url中的id参数。。如果它不存在,那么它将分配到1000,如果存在,那么我们将增加它,并在7秒后调用document.location。感谢代码,但它不起作用。。。事实上,它不是通过URL的我想通过它循环兄弟…它将通过URL循环。。。将演示URL更改为原始URL。我们已经在当地测试了它,它正在工作。我已经用原来的一个替换了这个演示。。。但它只增加了1,然后又停止了。我正在运行这是控制台窗口,我已经删除了lines脚本标记,我已经运行了它,但没有工作:我在这里添加了代码:它工作得很好。我感谢你的努力,兄弟。。但是我很抱歉我不知道我。。。你能给我更多的细节或演示如何使用它,并解决这个问题,这将是非常大的帮助…而不是把ii纳入函数调用,请使它全球化为什么?当函数在7秒后执行时,ii变量的作用域会发生变化。我认为你需要阅读和理解代码,以了解为什么这不重要。你检查过演示URL了吗
<script type="text/javascript">
        function getParameterByName(name, url) {
            if (!url) url = window.location.href;
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }
        var idVal = getParameterByName("id");
        if(idVal== "" || idVal == null){
            idVal = 1000;
        }else{
            idVal++;
        }

        setTimeout(function(){
            console.log("Next");
            this.document.location = "http://website.com/page.php?id=" + idVal;
        }, 7000);

    </script>