【发布时间】:2020-10-27 09:35:21
【问题描述】:
我正在使用 YouTube Player 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-consent 和 data-consent-src。我还需要将 src 设置为空:
<iframe width="560" height="315" src="" data-category-consent="cookie_cat_statistic" data-consent-src="https://www.youtube.com/embed/3EeY_7ujsew" frameborder="0" allow="autoplay;"></iframe>
在读取页面 DOM 并继续使用 YouTube 播放器 API之前,有什么方法可以对 iFrame 执行这些更改?在获得同意之前,我需要避免使用 YouTube-cookie,这意味着在添加属性之前无法读取 iFrame。
【问题讨论】:
标签: javascript html youtube-api