jquery - YouTube API: custom button to start playing an embedded video -
i have embedded youtube video in website, want start playing clicking on custom button outside player.
after research on web i've tried piece of js:
$(document).ready(function() { $.getscript('http://www.youtube.com/player_api'); $('#playvideo').click( function() { thevid=document.getelementbyid('thevideo'); thevid.style.display='block'; this.style.display='none'; $('#video').playvideo(); }); }); where #playvideo button , #video youtube iframe.
and embedding html code:
<iframe id="video" width="266" height="150" src="http://www.youtube-nocookie.com/embed/ujnhin-gszm?rel=0&showinfo=0&controls=2&enablejsapi=1" frameborder="0" allowfullscreen></iframe> but it's not working on browser , i'm receiving js error:
uncaught typeerror: object [object object] has no method 'playvideo'
anyone can give me suggestion?
you referencing video id of thevideo here:
document.getelementbyid('thevideo')
but later try referencing video id of video here:
$('#video').playvideo();
make sure of ids , references correct. let know if problem persists.
Comments
Post a Comment