Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click a browser button with JavaScript automatically?

How to click a button every second using JavaScript?

like image 647
001 Avatar asked Dec 23 '10 04:12

001


People also ask

How do you make a button click itself in JavaScript?

You use document. getElementById("button-id"). click() to click your button.

How do I automatically press a button in HTML?

If you want it to repeat, just call the function that's set to the click listener of clickButton . Unless you mean over and over, in which case use setInterval or setTimeout (less recommended). I put the code within my page: <head> <script type="text/javascript"> window. onload = function(){ document.


4 Answers

setInterval(function () {document.getElementById("myButtonId").click();}, 1000);
like image 107
John Hartsock Avatar answered Oct 20 '22 01:10

John Hartsock


This will give you some control over the clicking, and looks tidy

<script>
var timeOut = 0;
function onClick(but)
{
    //code
    clearTimeout(timeOut);
    timeOut = setTimeout(function (){onClick(but)},1000);
}
</script>
<button onclick="onClick(this)">Start clicking</button>
like image 32
Isaac Avatar answered Oct 20 '22 00:10

Isaac


document.getElementById('youridhere').click()
like image 5
KonaRin Avatar answered Oct 20 '22 01:10

KonaRin


This would work

setInterval(function(){$("#myButtonId").click();}, 1000);
like image 2
Meuru Avatar answered Oct 20 '22 00:10

Meuru