Demo . Switching tabs pauses the playback of any videos.
Using the YouTube Player API , you can play / pause / stop the video.
<script src="//www.youtube.com/iframe_api"></script> <iframe width="510" height="287" src="//www.youtube.com/embed/VIDEO_ID?enablejsapi=1" frameborder="0" allowfullscreen></iframe> <script> $(function(){ $('iframe[src*="//www.youtube.com/embed/"]').each(function(i) { this.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*'); }); }); </script>
Note the query string ?enablejsapi=1 added to the YouTube embed url in the iframe .
source share