Javascript simulates a mouse click at a specific position

I need now how to automatically activate the mouse click event on the button. I have this but not working :(

window.setInterval (function () {simulateClick ();}, 2000);

function simulateClick () {
    var evt = document.createEvent ("MouseEvents");
    evt.initMouseEvent ("click", false, false, window, 0, 684, 571, 684, 508, false, false, false, false, 0, null);
        var a;
    a.dispatchEvent (evt);
}

Thanks in advance

Oscar

+3
source share
2 answers

If all you want to do is click a button, the button elements have a method clickthat can be called:

<input type="button" id="theButton" onclick="javascript:alert('The button was clicked!');" value="A button" />

<script language="javascript">

setTimeout(function(){
    document.getElementById("theButton").click();
}, 1000); // wait one second then click the button

</script>

"" x, y.

+2

, javascript, , , , autohotkey

+1

All Articles