Question

I use Youtube subscribe button (https://developers.google.com/youtube/youtube_subscribe_button ).

Is there any way, while user clicks on it, to initiate my javascript function too?

Was it helpful?

Solution

You just need to add a data element with the function that you need to run.

<script>
function myEvent(e) 
{ 
    // do something here 
}
</script>

<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-onytevent="myEvent"></div>

https://developers.google.com/youtube/youtube_subscribe_button#Handling_Events_Demo

OTHER TIPS

just put the name of your function in an onclick like so:

<div id="whatever they make you call it" onclick="yourFunction();" />

or do this in javascript

document.getElementById("whatever it's called").onclick = "yourFunction();";

I'm not saying it's a good idea, and it will probably violate their terms of use, but this is what I would try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top