Last active
June 10, 2016 14:44
-
-
Save xto3na/5eda9f88a487245cc630d988a496a7d6 to your computer and use it in GitHub Desktop.
STOP Youtube-video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="video-wr"> | |
<iframe width="490" height="300" src="https://www.youtube.com/embed/2CPY5C-PYPs?enablejsapi=1" frameborder="0" allowfullscreen></iframe> | |
</div> | |
<button type="button" class="btn btn-primary stop-btn">PAUSE</button> | |
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
//Initializing video for Enable jsapi | |
// For each of them: | |
$("iframe").each(function() { | |
// If "enablejsapi" is not set on the iframe's src, set it: | |
if (this.src.indexOf("enablejsapi") === -1) { | |
// ...check whether there is already a query string or not: | |
// (ie. whether to prefix "enablejsapi" with a "?" or an "&") | |
var prefix = (this.src.indexOf("?") === -1) ? "?" : "&"; | |
this.src += prefix + "enablejsapi=true"; | |
} | |
}); | |
var func = 'pauseVideo'; // OR 'playVideo' or 'stopVideo' if need to play | |
$(".stop-btn").on("click", function() { | |
$("iframe").each(function() { | |
this.contentWindow.postMessage('{"event":"command","func":"' + func + '","args":""}', '*'); | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment