Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
Javascript 重新加载iframe,并尽可能多地单击iframe内的按钮 window.onhashchange=函数(){ setTimeout(函数(){ 让frame=document.querySelector(“body>iframe”); 如果(frame!==null){frame.replacetwith(frame);} }, 1000); } //重新加载iframe var i=0; 而(i{DStuff()},3000) onhashchange(); i++; } //点击按钮_Javascript - Fatal编程技术网

Javascript 重新加载iframe,并尽可能多地单击iframe内的按钮 window.onhashchange=函数(){ setTimeout(函数(){ 让frame=document.querySelector(“body>iframe”); 如果(frame!==null){frame.replacetwith(frame);} }, 1000); } //重新加载iframe var i=0; 而(i{DStuff()},3000) onhashchange(); i++; } //点击按钮

Javascript 重新加载iframe,并尽可能多地单击iframe内的按钮 window.onhashchange=函数(){ setTimeout(函数(){ 让frame=document.querySelector(“body>iframe”); 如果(frame!==null){frame.replacetwith(frame);} }, 1000); } //重新加载iframe var i=0; 而(i{DStuff()},3000) onhashchange(); i++; } //点击按钮,javascript,Javascript,我想刷新iframe并尽可能多地单击按钮。当我运行这个脚本时,它不会循环。此外,脚本还应在单击按钮后等待一秒钟 放弃循环,只需使用setInterval: window.onhashchange = function () { window.setTimeout(function () { let frame = document.querySelector("body > iframe"); if (frame !== nu

我想刷新iframe并尽可能多地单击按钮。当我运行这个脚本时,它不会循环。此外,脚本还应在单击按钮后等待一秒钟

放弃循环,只需使用setInterval:

window.onhashchange = function () {
        window.setTimeout(function () {
            let frame = document.querySelector("body > iframe");
            if (frame !== null) {frame.replaceWith(frame);}
        }, 1000);
    }
//reload the iframe
var i = 0;
while (i < 100) {
    async function DStuff(){
        await document.querySelector("#Btn").click()
    }
    setTimeout(() => { DStuff() }, 3000)
    window.onhashchange();
    i++;
}
//click button
上面的操作将等待3秒钟,直到再次单击为止,同时在达到100次单击后停止。
不用说,iFrame必须在同一个域上,否则由于跨站点限制,它将无法访问。

放弃循环,只需使用setInterval:

window.onhashchange = function () {
        window.setTimeout(function () {
            let frame = document.querySelector("body > iframe");
            if (frame !== null) {frame.replaceWith(frame);}
        }, 1000);
    }
//reload the iframe
var i = 0;
while (i < 100) {
    async function DStuff(){
        await document.querySelector("#Btn").click()
    }
    setTimeout(() => { DStuff() }, 3000)
    window.onhashchange();
    i++;
}
//click button
上面的操作将等待3秒钟,直到再次单击为止,同时在达到100次单击后停止。
不用说,iFrame必须在同一个域上,否则由于跨站点限制,它将无法访问。

如果您想在重新加载和单击之间使用不同的时间延迟,可以使用两个递归调用对方的函数,使用计数停止循环:

var-totalIterations=0;
函数clickButton(){
日志(“点击按钮调用”)
//您的点击按钮代码在这里
//document.querySelector(“#Btn”)。单击()
//在1秒内,调用reload frame函数
设置超时(重新加载帧,1000)
}
函数重载帧(){
log(“重新加载调用的帧”)
//在此处重新加载帧代码:
//让frame=document.querySelector(“body>iframe”);
//如果(frame!==null){frame.replacetwith(frame);}
//如果我们还没有运行100次,请在3秒钟内运行“单击”按钮
如果(总迭代次数<100){
设置超时(单击按钮,3000)
总迭代++
}
}
//调用函数以启动

clickButton()
如果要在重新加载和单击之间使用不同的时间延迟,可以使用两个递归调用的函数,并使用计数停止循环:

var-totalIterations=0;
函数clickButton(){
日志(“点击按钮调用”)
//您的点击按钮代码在这里
//document.querySelector(“#Btn”)。单击()
//在1秒内,调用reload frame函数
设置超时(重新加载帧,1000)
}
函数重载帧(){
log(“重新加载调用的帧”)
//在此处重新加载帧代码:
//让frame=document.querySelector(“body>iframe”);
//如果(frame!==null){frame.replacetwith(frame);}
//如果我们还没有运行100次,请在3秒钟内运行“单击”按钮
如果(总迭代次数<100){
设置超时(单击按钮,3000)
总迭代++
}
}
//调用函数以启动

clickButton()
您基本上是在(几乎)同一时间设置100个3秒超时,因此每个超时都将在同一时间结束,并在3秒后运行
DStuff
100次。那么如何在DStuff之后运行window.onhashchange?我不擅长javascript。请帮我解决我的noob问题。你基本上是在(几乎)同一时间设置100个3秒超时,因此每个超时都将在同一时间结束,并在3秒后运行
DStuff
100次。那么如何在DStuff之后运行window.onhashchange呢?我不擅长javascript。请帮我解决我的noob问题。它给了我未捕获的TypeError:无法读取null的属性“click”。我认为它并没有得到按钮,因为它试图点击按钮,直到页面加载。它在我的测试中工作得很好。问题是:它给了我未捕获的TypeError:无法读取null的属性“click”。我认为它并没有得到按钮,因为它试图点击按钮,直到页面加载。它在我的测试中工作得很好。这是小提琴: