Auto Click mouse on a content within a div?

2

I would like to know if it is possible to do a div with auto click.

This is how the page loads and when someone clicks anywhere on the page the mouse clicks on the content inside the div.

In case I put an iframe from an external page. but it could be an image or a video.

If possible do this with java script. and that once the click has happened the same person can not click again for 1 day. or a time interval.

 <div id='conteudo'>  
 <iframe frameborder='0' height='260' name='iframe1' scrolling='no' src='url' width='336/>   
</div>
    
asked by anonymous 29.05.2015 / 22:04

2 answers

3

That way it will not work, because you're actually clicking on the element inside the iframe. Using jquery you can use the contents method inside the iframe

It would look like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
var iframeContents = $('iframe').contents()[0];
$(iframeContents).find('seletor').click(function () {
// Aqui entra o seu evento!
});
    
29.05.2015 / 22:33
0

As long as you have an

event linked to your area (which I'll call #meu_elemento ), you can do something like this:

$('#meu_elemento').trigger('click');

You can leave the event as the default of the element, or make a bind

$('#meu_elemento').on('click', function(e){
    $('.target').append('você clicou em #meu_elemento');
});

See the working example:

$('#meu_elemento').on('click', function(e){
    $('.target').append('você clicou em #meu_elemento');
});


setTimeout((function() {
    $('#meu_elemento').trigger('click');
}), 5000);
#meu_elemento{
    width: 100px;
    height: 100px;
    background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="meu_elemento"></div>

<div class="target"></div>

Notice that I've put setTimeout() into trigger() so you can see it in action (note that clicking the red square repeats the event). What it does is a simple append() of a text. From there, you can treat your click event as you see fit.

    
29.05.2015 / 23:36