Skip to content

Instantly share code, notes, and snippets.

@anam-hossain
Created May 8, 2015 01:49
Show Gist options
  • Select an option

  • Save anam-hossain/7a10734514a9c53d88a8 to your computer and use it in GitHub Desktop.

Select an option

Save anam-hossain/7a10734514a9c53d88a8 to your computer and use it in GitHub Desktop.
Full example - autoplay youtube video in a Modal (Bootstrap + Jquery)
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
$(function() {
$(".video").click(function () {
var theModal = $(this).data("target"),
videoSRC = $(this).attr("data-video"),
videoSRCauto = videoSRC + "?modestbranding=1&rel=0&controls=0&showinfo=0&html5=1&autoplay=1";
$(theModal + ' iframe').attr('src', videoSRCauto);
$(theModal + ' button.close').click(function () {
$(theModal + ' iframe').attr('src', videoSRC);
});
});
});
</script>
</head>
<body>
<button class="btn btn-success btn-lg video" data-video="https://www.youtube.com/embed/8L5PqL4ylIU" data-toggle="modal" data-target="#videoModal">Play Video 1</button>
<button class="btn btn-default btn-lg video" data-video="https://www.youtube.com/embed/HBdcL7YsdBY" data-toggle="modal" data-target="#videoModal">Play Video 2</button>
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<iframe width="100%" height="350" src="" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
</body>
</html>

ghost commented Apr 2, 2018

Copy link
Copy Markdown

but guys can anybody make popup video like this, here you can see - popup video of adobe photoshop - https://www.adobe.com/in/products/photoshop.html

@donaFabris

Copy link
Copy Markdown

This helped me a lot, thank you! Do you know why if I modify the CSS of the buttons with my own CSS the whole function stops working? Is there another way to modify the design of the buttons? Thank you!

@labar

labar commented Dec 10, 2018

Copy link
Copy Markdown

This just helped me figure out my issue. Thanks a lot!

@jhonhenrybernal

Copy link
Copy Markdown

La rompiste me funciono perfectamente

@emb03

emb03 commented Aug 22, 2019

Copy link
Copy Markdown

This saved my butt! Thank you!!!!

@patapouf123

Copy link
Copy Markdown

Hello for always launch autoplay
replace <iframe width="100%" height="350" src="" frameborder="0" allowfullscreen></iframe>
by

<iframe width="100%" height="350" src="" frameborder="0" allowfullscreen allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture">

Thanks

@harry9345

Copy link
Copy Markdown

well done

@manojsukale

Copy link
Copy Markdown

Not working in Mobile can anyone tell me the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment