Javascript: Hide button after "subscribe" event

Asked

Viewed 79 times

0

People in this google script have a comment written "Add code to Handle subscribe Event." translating "Add code to handle signature event.".

I want to know if there is a way I can put a code in this place so that when the "subcribe" action occurs the button disappears. If there’s a way and you know the code, you can give it to me?

<script src="https://apis.google.com/js/platform.js"></script>

<script>
  function onYtEvent(payload) {
    if (payload.eventType == 'subscribe') {
      // Add code to handle subscribe event.
    } else if (payload.eventType == 'unsubscribe') {
      // Add code to handle unsubscribe event.
    }
    if (window.console) { // for debugging only
      window.console.log('YT event: ', payload);
    }
  }
</script>

<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>

  • If Voce can edit the code/div of the button put one id in it and hide in the subscribe if. If the button is being automatically generated it is a little different. And what is this api that is using?

  • Google Developers

  • https://developers.google.com/youtube/youtube_subscribe_button?hl=pt-br

  • is using jquery too?

  • No, only html and js

1 answer

1

This already resolves, if you are using jquery, it will not be different, instead of removing the boot could only hide Div too, there depends on what you need.

<script>
  function onYtEvent(payload) {
    if (payload.eventType == 'subscribe') {
      // Add code to handle subscribe event.
      document.getElementById('inscreverse').remove();
    } else if (payload.eventType == 'unsubscribe') {
      // Add code to handle unsubscribe event.
    }
    if (window.console) { // for debugging only
      window.console.log('YT event: ', payload);
    }
  }
</script>

<!-- como a api manipula a div  g-ytsubscribe entao eu coloqeui essa div para ser mais facil de esconder o botao depois -->
<div id="inscreverse">
  <!-- adicionei um texto e um evento de click no botao,somente para simular o que aconteceria, pode tirar quando for o codigo final -->
  <div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="default" data-count="default" data-onytevent="onYtEvent" onClick="onYtEvent({eventType:'subscribe'})">inscrever-se </div>
 </div>

  • Hide the div is even better because I palenejo put a blocker that only beat the download button for who sign up, so I want the button to disappear in case the person is enrolled, what did helped me understand, but I need to do with the sign-up buttonif youtube that I will put on the site.

  • Thanks for your help man :-D

Browser other questions tagged

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