javascript - Youtube video on load through Jquery/JS -
my goal display youtube video through javascript function read embedded code , load video automatically in div assigned. not getting shown in div assigned video. because has triggered button click?
<script type="text/javascript"> var last_cnad_text_1 = ''; var options_cnad_text_1 = { embedmethod:'fill', maxwidth:320, maxheight: 320 }; function loadvideo() { val = $('#cnad_text_1').val(); if ( val != '' && val != last_cnad_text_1 ) { last_cnad_text_1 = val; $("#embed_cnad_text_1").oembed(val,options_cnad_text_1); } } $(function(){ $('#cnad_text_1').keydown(loadvideo()); $('#cnad_text_1').click(loadvideo()); $('#cnad_text_1').change(loadvideo()); }); </script> <body> <input id="cnad_text_1" type="text" value="" size="60" name="cnad[text_1]"> <div id="embed_cnad_text_1"></div> </body> </html>
youtube provides autoplay option in api:
https://developers.google.com/youtube/player_parameters#autoplay
just set autoplay=1 in api request.
here simple example autoplays: http://jsfiddle.net/tnujt/
Comments
Post a Comment