Javascript 从YouTube播放器API向iframe添加HTML属性

Javascript 从YouTube播放器API向iframe添加HTML属性,javascript,html,youtube-api,Javascript,Html,Youtube Api,我正在使用YouTube播放器API在网站上嵌入视频: let player = new YT.Player(videoElementID, { height: '390', width: '640', videoId: videoElementID, host: 'https://www.youtube-nocookie.com', playerVars: { origin: window.location.h

我正在使用YouTube播放器API在网站上嵌入视频:

    let player = new YT.Player(videoElementID, {
      height: '390',
      width: '640',
      videoId: videoElementID,
      host: 'https://www.youtube-nocookie.com',
      playerVars: {
        origin: window.location.host,
        showinfo: 0,
        rel: 0,
        hl: 'da-dk'
      }
但是现在需要向视频iFrame添加不受支持的属性,特别是属性data category Approvement和data Approvement src。我还需要将src设置为空:


有没有办法在读取页面DOM之前对iFrame执行这些更改,并继续使用YouTube播放器API?我需要在同意之前避免使用YouTube Cookie,这意味着在添加属性之前无法读取iFrame。

基本上不使用库,创建iFrame并自己填充

由于以下原因,此示例在此处不起作用:

已阻止跨源请求:同一源策略不允许读取 远程资源

onclick=()=>{
yt.innerHTML=``
}
点击加载播放器

我们也有类似的需求。因此,通过JQuery添加了数据类别同意和数据同意src。实施情况如下:

<div id="playerId"></div>

<script>
new YT.Player(playerId, {
      height: '390',
      width: '640',
      videoId: videoElementID,
      host: 'https://www.youtube-nocookie.com',
      playerVars: {
        origin: window.location.host,
        showinfo: 0,
        rel: 0,
        hl: 'da-dk'
      }

 
$('iframe#playerId').attr(
{
       "data-category-consent": "cookie_cat_marketing",
       'data-consent-src': $('iframe#playerId').attr("src");
       "src":""
 });

</script>

新YT.球员(球员ID{
高度:“390”,
宽度:“640”,
videoId:videoElementID,
主持人:'https://www.youtube-nocookie.com',
playerVars:{
原点:window.location.host,
showinfo:0,
rel:0,
hl:‘dadk’
}
$('iframe#playerId').attr(
{
“数据类别同意”:“cookie\u cat\u营销”,
“数据同意src”:$(“iframe#playerId”).attr(“src”);
“src”:”
});