简体   繁体   中英

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. I am inserting the videos with the featured media options. Therefore I cannot add the attribute preload="none" to my video-tag.

So I was trying to manage it with javascript, like:

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.

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.

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

Also, it's worth noting that the preload attribute does not work in Internet Explorer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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