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!
Asked
Active
Viewed 141 times
-4
-
just random clicking? or targeting a specific element? – cts Mar 08 '23 at 09:48
-
1random clicking – denoryprogrammer Mar 08 '23 at 09:51
2 Answers
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
-
then, the user needs to input the id of the button first, thats not really wat i want... – denoryprogrammer Mar 08 '23 at 09:51
-
-
-
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