Goal: Once the page is loaded a random area on the screen is clicked. Not a certain button or element, just a random click.
Maybe add an if function that if the click is successful then do another function?
Goal: Once the page is loaded a random area on the screen is clicked. Not a certain button or element, just a random click.
Maybe add an if function that if the click is successful then do another function?
using jquery, an approach can be...
var posx = (Math.random() * ($(document).width())).toFixed();
var posy = (Math.random() * ($(document).height())).toFixed();
$('body').append($("<div class=myclass style=left:"+posx+"px;top:"+posy+"px;>Hello from random!</div>"));
$( ".myclass" ).click(function() {
alert( "random area clicked." );
});
.myclass{
position:absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
What about taking all divs, choosing a random one and click on it?
window.onload=function(){
var els=document.getElementsByClassName("*");
els[Math.round((els.length-1)*Math.random())].click();
};
And a click cannot be successful, and you cannot detect that...