简体   繁体   English

防止HTML5视频在Wordpress中预加载

[英]Prevent html5 video from preloading in wordpress

I have a wordpress page with lots of videos and would like to stop the preload with html5. 我有一个包含大量视频的wordpress页面,并希望停止使用html5进行预加载。 I am inserting the videos with the featured media options. 我要插入带有特色媒体选项的视频。 Therefore I cannot add the attribute preload="none" to my video-tag. 因此,我无法将属性preload =“ none”添加到我的视频标签中。

So I was trying to manage it with javascript, like: 所以我试图用javascript来管理它,例如:

function videoPreload () {
    document.getElementsByTagName('video').setAttribute('preload', 'none');
};
videoPreload();

But it doesn't work. 但这是行不通的。 I get the error, that this function does not exist. 我收到错误消息,该函数不存在。 How can I add the relevant attribute to stop the videos from preloading? 如何添加相关属性以阻止视频预加载?

Thanks so much! 非常感谢!

The problem is that document.getElementsByTagName returns an array of all video elements. 问题在于document.getElementsByTagName返回所有视频元素的数组。

I would change your code to either reference a single video 我将更改您的代码以引用单个视频

document.getElementsByTagName('video')[0].setAttribute('preload', 'none');

or add an id to your video element and reference that. 或为您的视频元素添加ID并引用该ID。

document.getElementById("myVid").setAttribute('preload', 'none');

Also, it's worth noting that the preload attribute does not work in Internet Explorer. 另外,值得注意的是,preload属性在Internet Explorer中不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM