Catch event click inside iframe with jQuery

Asked

Viewed 775 times

5

I’m using the Google Forms to do a satisfaction survey on a site. On this site I show a bar at the top, asking the user to participate. If he closes the message, a cookie is saved that expires in 24 hours so that he no longer sees the message that day.

I would like to record a cookie if the user responds to the questionnaire so that he no longer sees the message on the site.

Someone knows a way to do it?

Editing: I can record the cookie with jQuery.
Is there any way to get the form click event? Via javascript or jquery. It is in an iframe and I can’t use jquery, for example, and catch the click event.

Iframe:

<iframe src="endereco_do_form" width="955" height="700" frameborder="0" marginheight="0" marginwidth="0">Carregando...</iframe>

Jquery:

<script>
    $('#ss-submit').click(function(e){
      e.preventDefault();
      alert("OK")
    });
</script>
  • #ss-Submit is the button id. I got it from devtools.

  • I saw that I cannot take the event because of the policies of the same origin. Does anyone know any way to do this?

  • From what I understand, you cannot interact with the content of an iframe coming from a domain other than your website. But you can create a CLOSE button outside the iframe and save the cookie valid for 24h. In case the user responds to the search, you need a Google callback with the search ID that will be sent to your site so that you identify this and record a cookie with "unlimited" validity so that the search no longer appears to that user.

1 answer

1

To see the contents of this iframe do this: var frame = window.frames[0]. Document; The . frames[0] -> 0 represents the only iframe on the screen, if there is another need to put which iframe index.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.