Help in javascript

1

How do I make this script run in 10 seconds ??

<script type = "text/javascript">

function simulateClick(x, y) {

var clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, x, y, false, false, false, false, 0, null);
document.elementFromPoint(x, y).dispatchEvent(clickEvent);

}
simulateClick(1176, 435);
</script> 

The idea would be to put a countdown on it, does anyone know?

    
asked by anonymous 23.10.2015 / 00:28

1 answer

5

The setTimeout function can be used to invoke a function after X milliseconds:

var timeoutID = setTimeout(simulateClick, 10000, 1176, 435);

The first parameter is the function that will be called, the second the number of milliseconds to wait (10s = 10000ms). The additional parameters are passed directly to the function, ie it is almost the same as doing:

setTimeout(function() { simulateClick(1176,435); }, 10000);

( Note: if you want to support IE9 or earlier, always use this second format because the first one is not supported)

The return value can be ignored if you do not need it. It is used if you want to cancel the function call before it occurs, via clearTimeout(timeoutID) .

    
23.10.2015 / 05:56