-4

I'm making a autoclicker chrome browser extension, but how can I simulate a mouse click using javascript? And how can i make the it click on a random spot of the screen? Thanks for helping!

2 Answers2

2

Simply by click() function.

document.getElementById('mybutton').click();

If you want a random click use:

let els = document.querySelectorAll('body *');
var rand = Math.floor( Math.random() * els.length );
els[rand].click();
Alijvhr
  • 1,695
  • 1
  • 3
  • 22
0

Create a button with an id & onClick function:

<button id="clickMe" onclick="clicked()">Click Here</button>

Call the click function:

document.getElementById("clickMe").click();

Add this loop to automate 1000 clicks!

for ( let i = 0; i < 1000; i++ ) {
  document.getElementById("clickMe").click();
}
cts
  • 908
  • 1
  • 9
  • 30