0 points

Stop YouTube Embedded Video from Playing with Javascript


dashboard

Fri Dec 13 2019 12:47:41 GMT+0000 (UTC)

Posted by @mishka #html #javascript

<main>
	<iframe src="https://www.youtube.com/embed/KQetemT1sWc"></iframe>   
    <a href="#!" onclick="stopThis()">Stop Playing</a>
</main>

<script>
  function stopThis(){
      var iframe = container.getElementsByTagName("iframe")[0];
      var url = iframe.getAttribute('src');
      iframe.setAttribute('src', '');
      iframe.setAttribute('src', url);
  }
</script>
content_copy Copy