skip to Main Content

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

Answers


  1. 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();
    
    Login or Signup to reply.
  2. 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();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search