我需要在 500 次收集或我告诉它多少次收集后停止点击


I need onclick to stop after 500 collects or how ever many i tell it to

这基本上是一个链接中继器,我不知道如何让它在我想要的数字后停止。假设我希望它重复一个链接 500 次,然后我希望它停止。这可能吗?请帮忙。

<html>
<head>
    <script>
        var a=0;
        var milli;
        function collect1()
        {
            var milli = document.getElementById("numbers").value;
            var links=document.getElementById('linkholder').value;
            links = links.replace(/['n'r]/gi , " ");
            var link=links.split(" ",100000);
            var iframe1=document.getElementById('iframe1');
            iframe1.onload = function(){setTimeout(collect1, milli);};
            iframe1.src=link[a];
            a++;
            var count1=document.getElementById('count1');
            count1.innerHTML='&nbsp;&nbsp;&nbsp;&nbsp;'+a+' Collected';
            if (a >= link.length){a=0;}
        }
        function refreshgifts(){
        var invurl = document.getElementById('invurl').value;
        var iframeg=document.getElementById('inventory');
        iframeg.src = invurl;}
    function refreshinv(){
    var gifturl = document.getElementById('gifturl').value;
    var iframei=document.getElementById('stash');
    iframei.src = gifturl;}
    </script>
</head>
<body>
<textarea id="linkholder" cols="50" rows="4"></textarea></br>
<input id="numbers" type="number" value="1000"></input>
<button onclick="collect1();">Start</button>
    <div><div id="count1">0 Collected</div><iframe id="iframe1" src=""  style="width:700px;height:80px;" onload=""></iframe></div>
</br></br>
<button onclick="refreshgifts();">Refresh Gifts</button><input type="text"  style="overflow:hidden;" id="invurl"></input>
    <div><iframe id="inventory" src="" style="width:600px;height:200px;" onload=""></iframe></div>
<button onclick="refreshinv();">Refresh Stash</button><input type="text" style="overflow:hidden;" id="gifturl" ></input>
    <div><iframe id="stash" src="" style="width:600px;height:200px;" onload=""></iframe></div>
</body>
</html>

尝试以下代码

<html>
    <head>
        <script>
            var a=0,b=0;
            var milli;
          var cnt=1;
            function collect1()
            {
                var milli = document.getElementById("numbers").value;
                var links=document.getElementById('linkholder').value;
                var maxtimes=document.getElementById("maxtimes").value;
                var count1=document.getElementById('count1');
                links = links.replace(/['n'r]/gi , " ");
                var link=links.split(" ",100000);
                var iframe1=document.getElementById('iframe1');
                //iframe1.onload = function(){setTimeout(collect1, milli);};
                iframe1.onload = function(){
                if(cnt<maxtimes) //maximum number that you wanted has to go here
                setTimeout(
                   function(){
                      collect1();
                      //count1.innerHTML+=" /"+cnt+" time(s), it run";
                      cnt++;
                   }, milli)
                else cnt=1;
                }
                iframe1.src=link[a];
                a++;b++;
                count1.innerHTML='&nbsp;&nbsp;&nbsp;&nbsp;'+a+' Collected'+" /"+b+" time(s), it run";;
                if (a >= link.length){a=0;}
            }
            function refreshgifts(){
            var invurl = document.getElementById('invurl').value;
            var iframeg=document.getElementById('inventory');
            iframeg.src = invurl;}
        function refreshinv(){
        var gifturl = document.getElementById('gifturl').value;
        var iframei=document.getElementById('stash');
        iframei.src = gifturl;}
        </script>
    </head>
    <body>
    <textarea id="linkholder" cols="50" rows="4"></textarea></br>
    <input id="numbers" type="number" value="1000"></input>
    Number of Times:<input id="maxtimes" type="number" value="500"></input>
    <button onclick="collect1();">Start</button>
        <div><div id="count1">0 Collected</div><iframe id="iframe1" src=""  style="width:700px;height:80px;" onload=""></iframe></div>
    </br></br>
    <button onclick="refreshgifts();">Refresh Gifts</button><input type="text"  style="overflow:hidden;" id="invurl"></input>
        <div><iframe id="inventory" src="" style="width:600px;height:200px;" onload=""></iframe></div>
    <button onclick="refreshinv();">Refresh Stash</button><input type="text" style="overflow:hidden;" id="gifturl" ></input>
        <div><iframe id="stash" src="" style="width:600px;height:200px;" onload=""></iframe></div>
    </body>
    </html>