Skip to main content

How to stop and pause youtue video in jquery?

How to stop and pause youtue video in jquery?



                               Html



<iframe width="560" height="315" src="https://www.youtube.com/embed/mKt-MDwtVB4" frameborder="0" allowfullscreen></iframe>

  <button class="fancybox-close">Stop video please</button>

<p>
http://stackoverflow.com/questions/8931798/hide-show-in-javascript-stop-playing-youtube-iframe-video

http://stackoverflow.com/questions/9482180/using-javascript-to-add-class-to-youtube-iframe-element

http://stackoverflow.com/questions/4249809/reload-an-iframe-with-jquery
</p>

                                   CSS


body {width:60%;margin:3em auto;}
footer {border-top:1px solid #ccc;padding:1em 0;}



jQuery


    // Finds all iframes from youtubes and gives them a unique class
    jQuery('iframe[src*="https://www.youtube.com/embed/"]').addClass("youtube-iframe");

    jQuery(".fancybox-close").click(function() {
      // changes the iframe src to prevent playback or stop the video playback in our case
      $('.youtube-iframe').each(function(index) {
        $(this).attr('src', $(this).attr('src'));
        return false;
      });
      
//click function
    });

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...