Skip to content

Instantly share code, notes, and snippets.

@anam-hossain
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anam-hossain/a0527be17a59b18fc2c4 to your computer and use it in GitHub Desktop.
Save anam-hossain/a0527be17a59b18fc2c4 to your computer and use it in GitHub Desktop.
Autoplay youtube video in a Modal (Bootstrap + Jquery)
$(".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);
});
$(theModal).on('hidden.bs.modal', function (e) {
$(theModal + ' iframe').attr('src', videoSRC);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment