Szilvia Németh Szilvia Németh - 1 year ago 168
Javascript Question

Delay in javascript

I saw a lot of questions about how to put delay or sleep in javascript. I tried everything i just could not have the code work, like i wanted to.

So i get like 500 friend requests on facebook, kinda annoying accepting one them one by one. So i found the script which does accept all my friend requests at once. I tried the set time out and sleep codes, which actually do the work but i want to put the delay between each actions. With Set timeout, it just delays the whole script. So i wanna do like this:


1sec delay


1sec delay


1sec deleay...

Here is my original script:

var field = document.getElementsByName("actions[accept]");
for (i = 0; i < field.length; i++)
field[i].click() ;

Answer Source

The correct solution to your problem would be the following:

var field = document.getElementsByName("actions[accept]");
var index = 0;
function acceptFriends(){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download