How to disable auto-play for local video in iframe

后端 未结 8 1126
我在风中等你
我在风中等你 2020-12-29 21:08

How to disable auto-play for video when src is from my local pc?


         


        
8条回答
  •  既然无缘
    2020-12-29 21:48

    I've tried all the possible solutions but nothing worked for local video bindings. I believe best solution would be to fix using jQuery if you still wants to use iframes.

    $(document).ready(function () {
        var ownVideos = $("iframe");
        $.each(ownVideos, function (i, video) {                
            var frameContent = $(video).contents().find('body').html();
            if (frameContent) {
                $(video).contents().find('body').html(frameContent.replace("autoplay", ""));
            }
        });
    });
    

    Note: It'll find all the iframes on document ready and loop through each iframe contents and replace/remove autoplay attribute. This solution can be use anywhere in your project. If you would like to do for specific element then use the code under $.each function and replace $(video) with your iframe element id like $("#myIFrameId").

提交回复
热议问题