jQuery – 强制对生成的iframe执行单击操作,以便自动播放

我是jQuery / JS的新手,并尝试自动点击生成的iframe以便播放video,因为在iframesurl设置时不认为自动播放有效,是否有可能并且可能我错了?

小提琴: https : //jsfiddle.net/p7v34x57/1/

JS:

$.each($('iframe[src*="facebook.com/plugins/video"]'), function() { var getId = $(this).attr('src'); var player = $('
'); var id = fbvideoID(getId); player.attr('data-id', id); player.html(videoThumbFB(id)); player.on('click', videoIframeFB); var videoContainer = $('
'); videoContainer.append(player); $(this).replaceWith(videoContainer); }); function fbvideoID(frame) { var myRegexp = /2F(\d+)%/g; var match = myRegexp.exec(frame); return match[1]; } function videoThumbFB(id) { return '
'; } function videoIframeFB() { var wrap = $(''); wrap.attr("src", "//www.facebook.com/video/embed?video_id=" + $(this).attr('data-id') + "&autoplay=1"); wrap.attr("frameborder", "0"); wrap.addClass("facebook-iframe"); $(this).empty(); $(this).append(wrap); videoClickFB(); } function videoClickFB(){ $('.facebook-iframe').click(); }