首页 > 解决方案 > 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);

标签: javascripthtmliframe

解决方案


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);

推荐阅读