Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Modal stop Youtube video

I'm very new to javascript and trying to use Twitter bootstrap to get a good looking website up and running quickly. I know this has something to do with jquery, but I'm not sure how to stop my video when I push the close button or the close icon.

Can someone explain how I can get my video to stop playing because even when I close the window, I can still hear it in the background.

<!-- Button to trigger modal -->     <a href="#myModal" role="button" class="btn" data-toggle="modal"><img src="img/play.png"></a>  <!-- Modal -->   <div id="myModal" class="modal hide fade" tabindex="-1" role=labelledby="myModalLabel" aria-hidden="true">     <div class="modal-header">       <button type="button" class="close" data-dismiss="modal" aria>×</button>       <h3 id="myModalLabel">I am the header</h3>     </div>     <div class="modal-body">       <p><iframe width="100%" height="315" src="http:com/embed/662KGcqjT5Q" frameborder="0" allowfullscreen></iframe></p>     </div>     <div class="modal-footer">       <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>     </div>   </div> 
like image 789
catchmikey Avatar asked Dec 10 '12 10:12

catchmikey


People also ask

How do I stop a YouTube video from being modal closed?

First, copy the code to embed the video from YouTube site. Then, put the code inside the . modal-body element. To stop video automatically when you close the modal, toggle the URL value of YouTube's video iframe src attribute dynamically using the jQuery.

How do you stop a video from bootstrap modal is closed?

You can adjust this behaviour by adding in some Bootstrap javascript/jQuery that acts to stop the video if either the modal window is either clicked to close or the background is clicked to dismiss the modal.

How do I stop my modal from closing when I click the button?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

How do I keep my bootstrap modal from closing when I click the button?

To prevent closing bootstrap modal when click outside of modal window we need add properties data-backdrop="static" and data-keyboard="false" to button which we are using to show modal window like as shown following.


2 Answers

There is a nice proper way of doing this - see the comments in the approved answer to this post.

Couldn't get that working first time round myself though, and was in a rush, so I did a rather horrible hacky bit of code which does the trick.

This snippet 'refreshes' the src of the embed iframe, causing it to reload:

jQuery(".modal-backdrop, #myModal .close, #myModal .btn").live("click", function() {         jQuery("#myModal iframe").attr("src", jQuery("#myModal iframe").attr("src")); }); 
like image 21
RobCalvert123 Avatar answered Sep 28 '22 05:09

RobCalvert123


I know I'm 2+ years late, but since then, a couple of things have changed, with B3 the new way to perform this out of the box is this:

$("#myModal").on('hidden.bs.modal', function (e) {     $("#myModal iframe").attr("src", $("#myModal iframe").attr("src")); }); 

Have fun with Bootstrap!

like image 81
gmslzr Avatar answered Sep 28 '22 07:09

gmslzr