Stop YouTube video within iFrame on external Button click

前端 未结 3 2098
予麋鹿
予麋鹿 2021-02-12 17:43

I know there are similar questions to this, but I haven\'t quite been able to get it to work.

This code shows a YouTube video which is within an iframe. When a button (

3条回答
  •  情话喂你
    2021-02-12 18:21

    You need to reset the link of the video, i had a similar problem this is how i solved it, i used jQuery in the process.

    //First get the  iframe URL
    var url = $('#YourIFrameID').attr('src');
    
    //Then assign the src to null, this then stops the video been playing
    $('#YourIFrameID').attr('src', '');
    
    // Finally you reasign the URL back to your iframe, so when you hide and load it again you still have the link
    $('#YourIFrameID').attr('src', url);
    

    Check this answer

提交回复
热议问题