Removing annotations on embedded YouTube videos

2019-03-21 07:59发布

I've discovered that you can disable annotations on embedded YouTube videos by adding the parameter &iv_load_policy=3 to the url in the embed code.

Example:

<object width="425" height="344">
    <param name="movie" value="http://www.youtube.com/v/PMnEvKCtHBw&hl=en&fs=1&iv_load_policy=3"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed src="http://www.youtube.com/v/PMnEvKCtHBw&hl=en&fs=1&iv_load_policy=3" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object>

Is there any way to force this parameter on all YouTube embed urls on a webpage using javascript/jQuery?

(Sort of like this example where you force wmode transparent on all flash objects)

3条回答
混吃等死
2楼-- · 2019-03-21 08:12

Try this:

$('object').each(function(){ 
        var $param = $(this).children(':first-child');
        var newUrl = $param.attr('value') + '&iv_load_policy=3';
        $param.attr('value', newUrl);
}); 

Done quickly without testing....

Tested and works

查看更多
干净又极端
3楼-- · 2019-03-21 08:24

iv_load_policy=3 is the way to go. However there are nice embed code generators, to do it for you.

查看更多
放荡不羁爱自由
4楼-- · 2019-03-21 08:25

The new HTML5 player no longer uses this embed code, but I have just adapted this code to work with the iframe that is being embedded and have it working on my site. (Works with WordPress ombed too)

$("iframe").each(function() {
        var src = $(this).attr("src") + '&iv_load_policy=3';
        $(this).attr("src", src);
});
查看更多
登录 后发表回答