BootStrap close model window and reset iframe src

Issue : When we closes YouTube video in model window, It keeps playing in background.
Poopup is closed but you can hear Audio in background.

Solutions :

OPT – 1) YouTube : Reset same video url in iframe src ( For individual popups )
jQuery(document).ready( function() {
jQuery(“#myModal-video”).on(‘’, function () {
console.log(” video closed “);

jQuery(“#myModal-video iframe”).attr(“src”, jQuery(“#myModal-video iframe”).attr(“src”));



OPT – 2) YouTube : Clear video url in iframe src in model popup (For common popups )

jQuery(document).ready( function() {
jQuery(“#myModal-video“).on(‘’, function () {
jQuery(‘#youtube_iframe’).attr(‘src’, “”);

IF You want to remove Autoplay (autoplay=1) from all iframe

jQuery(“iframe”).each(function() {
var video_url = jQuery(this).attr(“src”);
video_url = video_url.replace(“autoplay=1”, “autoplay=0”);
jQuery(this).attr(“src”, video_url);

1) #myModal-video = Model window ID
#youtube_iframe = iframe ID under model window


Developer, Technology aficionado, Beer Lover and founder of Network. Who shares a keen interest about website development, health issues, cancer awareness and other fun stuff.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular

Most discussed