Sunday, 15 January 2017

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('hidden.bs.modal', 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('hidden.bs.modal', 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);
});


---------------------------------------------------------------------------

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

No comments:

Post a Comment