javascript - iframe 不加载视频
问题描述
这是我拥有的代码,它看起来对我来说是正确的。但是,它没有按应有的方式加载链接的视频。
var clickHandler3 = function()
{
var iframe = document.createElement("iframe");
iframe.setAttribute("src","https://www.youtube.com/watch?v=mXnJqYwebF8autoplay=1");
iframe.setAttribute("allow","autoplay");
iframe.style.width = "300px";
iframe.style.height = "250px";
document.body.appendChild(iframe);
};
window.addEventListener("load", setup);
解决方案
var clickHandler3 =function()
{
var iFrameElem = document.createElement("iframe");
iFrameElem.setAttribute('height', '315');
iFrameElem.setAttribute('width', '560');
iFrameElem.setAttribute('src', 'https://www.youtube.com/embed/mXnJqYwebF8autoplay=1&mute=1');
iFrameElem.classList.add('player');
bodyElem = document.querySelector('body');
bodyElem.innerHTML = '';
bodyElem.classList.add('center');
bodyElem.appendChild(iFrameElem);
};
window.addEventListener("load", setup);
推荐阅读
- r - 在 IF 条件下限制向量的 2 个边界
- android - 片段未附加到主机
- javascript - 我如何检测到键盘上的 V 键已被按下?
- python - Python Twilio 错误 - prolog 中不允许有内容。架构验证警告
- sql - 如何在 SQL 中结合约束 CHECK?
- python - 如何掷骰子直到掷出 20 个骰子 3 或更低 Python
- react-native - Redux 可以在 React Native 中存储令牌会话吗?
- parallel-processing - 减少共享内存库冲突
- typescript - 标记元组的类型级操作
- python - 具有行和列的 MultiIndex 数据框