1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to hide Youtube subscribe button when already subscribed

Discussion in 'JavaScript' started by KingCobra, Mar 28, 2016.

  1. #1
    Hello friends,

    I need your help for youtube subscribe button on my website. I need to hide the button for thos visitor who already subscribed my youtube channel (depends on if he logged in youtube/google). The button will be visible only to them who did not subscribe or not logged in youtube/google.

    I think to do the I need to check the button status then hide/show based on status. But I can't do it. So I am seeking your help.

    The code id bellow and also the youtube button generator page link:
    https://developers.google.com/youtube/youtube_subscribe_button

    <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>
    Code (markup):
     
    KingCobra, Mar 28, 2016 IP
  2. Sergey Yermak

    Sergey Yermak Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    Hi, i found different classes on that button when subscribed/unsubscribed. You can start from them:
    yt-uix-button-subscribe-branded
    yt-uix-button-subscribed-branded
     
    Sergey Yermak, Apr 1, 2016 IP
  3. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    KingCobra, Apr 1, 2016 IP
  4. Sergey Yermak

    Sergey Yermak Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    U can check the class and show/hide button with help of JS. Can u give me link to your page? mb i can help.
     
    Sergey Yermak, Apr 1, 2016 IP