문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top