Simulate click when opening the page

4

Is there a way, when someone enters a web site, a JavaScript event "simulate" a click ? In other words, JavaScript automatically makes a click on the site.

In case I have an ad that only opens when someone clicks the page. That is, you need to click the page to open a new advertising page.

<script data-cfasync="false" type="text/javascript" src="http://www.liveadexchanger.com/a/display.php?r=961387"></script>

Incasethereisaform,assoonassomeuserenters,openthispagebysimulatinga"click". Well I've tried all the ways they told me and I could not.

    
asked by anonymous 28.09.2015 / 21:56

3 answers

3

Just call click() on an element. Example:

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

Where meuElemento is the id of any element in html, as long as it has click event, such as elements input , button , a , div etc.

In order for it to be called on page load it must be within the window.onload :

window.onload = function()
{
    document.getElementById("meuElemento").click();
}

Fiddle 1 , Fiddle 2

    
28.09.2015 / 22:03
2

Do the following:

In Javascript:

function teste(){
   alert("Teste")
}
window.onload = function() {
   document.getElementById("elementoTeste").click();
}

No html:

<input type="button" onclick="teste()" id="elementoTeste">
    
28.09.2015 / 22:10
0

For me, I managed to make it work that way. Implemented the automatic click in 5000 mls and then I closed the loop after 1000 mls. Thus, only 1 automatic click.

<script> var myVar = setInterval(function ({document.getElementById("teste").click();}, 500); setInterval(function () {clearInterval(myVar)}, 1000); </script>
    
07.02.2017 / 13:54