Остановить видео YouTube в iFrame по внешнему нажатию кнопки

Я знаю, что есть похожие вопросы, но я неЯ вполне мог заставить его работать.

Этот код показывает видео YouTube, которое находится в пределах iframe. При нажатии кнопки (emsbinstartbutton) видео скрывается и заменяется заполнителем. Если этот местозаполнитель (threebytwo) видео должно показываться снова.

На данный момент это работает нормально, за исключением того, что когда видео скрыто, оно продолжит воспроизводиться (вы можете услышать звук, а когда вы вернетесь, вы увидите, что оно все еще воспроизводится). Видео должно быть остановлено, когда скрыто.

 



    


    
    
    

        // when they click on the buy now button we will hide the title and show the widget
        //detach work to stop vid but can t get it back.....
        $(document).ready(function () {
            $("#emsbinstartbutton").click(function () {
               $("#divbuyonlineVid").hide();
                $(".divbuyonlineVid").hide();
                $("#threebytwo").show();
            });
        });


        // when they click on the x the widget should be hidden and the video shows again
        $(document).ready(function () {
            $("#closebtn").click(function () {
                $("#divbuyonlineVid").show();
                $(".divbuyonlineVid").show();
                $("#threebytwo").hide();               
            });
        });

    
    
    
        #threebytwo
        {
            display: none;
        }
        #emsbin2startbutton
        {
            cursor: pointer;
        }
    


    
        
        <img class="emsbinstarttext" id="emsbinstarttext" src="http://static.e-talemedia.net/content/images/DoveYoutubeMessage.png">
        <img class="emsbinstartbutton" id="emsbinstartbutton" src="http://static.e-talemedia.net/content/images/DoveYoutubeBuyNowRed.png">
        alt="" />
        
            
        
    
    
        <img class="closebtn" id="closebtn" src="http://static.e-talemedia.net/content/images/DoveYoutubeExit.png">
        
            
                
                
                
                
                
                
            
        
    
    
    

Я пробовал следующее:

используя .detach и добавить
  // when they click on the buy now button we will hide the title and show the widget
        //detach work to stop vid but can t get it back.....
        $(document).ready(function () {
            $("#emsbinstartbutton").click(function () {
                $holdera = $("#divbuyonlineVid").detach();
                $holderb = $(".divbuyonlineVid").detach();
                $("#threebytwo").show();
            });
        });


        // when they click on the x the widget should be hidden and the video shows again
        $(document).ready(function () {
            $("#closebtn").click(function () {    
                $("#threebytwo").hide();
                alert($holdera);
                $("#divbuyonlineVid").append($holdera);
                alert($holderb);
                $(".divbuyonlineVid").append($holderb);
            });
        });

Даже если видео останавливается при щелчке, при попытке вернуться назад (Добавить) появляется сообщение об ошибке объекта.

Стоп и СтопВидео

Итак, в iframe, добавив:&enablejsapi=1

 

и в jQuery:

 $(document).ready(function () {
            $("#emsbinstartbutton").click(function () {
                $holdera = $("#divbuyonlineVid").hide();
                $holderb = $(".divbuyonlineVid").hide();
                $("#player").stop();
                $("#threebytwo").show();
            });
        });

Который нене могу ничего изменить. А также:

 $(document).ready(function () {
            $("#emsbinstartbutton").click(function () {
                $("#divbuyonlineVid").hide();
                $(".divbuyonlineVid").hide();
                $("#player").stopvideo();
                $("#threebytwo").show();
            });
        });

При нажатии кнопки вы все равно слышите звук, но три раза не показывает.

Я также добавил это:


Кто-нибудь может указать мне правильное направление или увидеть, где яя иду не так?

Изменить: shabeer90 описывает, как остановить видео YouTube, которое заставило меня на моем пути, но если вы просто хотели приостановить его и сохранить его в фоновом режиме, следующий код может быть полезным:

JQuery:

 
        $(document).ready(function () {
            var obj = $('object')
     .wrap('')
     .find('embed').attr('src', function (i, s) { return s + '&enablejsapi=1&version=3' }).end()
     .find('param[name=movie]').attr('value', function (i, v) { return v + '&enablejsapi=1&version=3' }).end()
     .detach()
     .appendTo($('#test'));

            $(document).ready(function () {
                $("#emsbinstartbutton").click(function () {
                    //Then assign the src to null, this then stops the video been playing
                    obj.find('embed')[0].pauseVideo();
                    $("body").append($("").css({
                        position: "fixed"
        , width: "640px"
        , height: "425px"
        , "background-color": "#000"
        , opacity: 0.6
        , "z-index": 999
        , top: 0
        , left: 0
                    }).attr("id", "page-cover"));

                    $("#threebytwo").show();
                });
            });

            // when they click on the x the widget should be hidden and the video shows again
            $(document).ready(function () {
                $("#closebtn").click(function () {
                    //                     $("#divbuyonlineVid").show();
                    //                     $(".divbuyonlineVid").show();
                    $("#threebytwo").hide();
                    $("#page-cover").detach();
                });
            });

        });
    

HTML:


        <img class="emsbinstarttext" id="emsbinstarttext" src="http://static.e-talemedia.net/content/images/DoveYoutubeMessage.png">
        <img class="emsbinstartbutton" id="emsbinstartbutton" src="http://static.e-talemedia.net/content/images/DoveYoutubeBuyNowRed.png" alt="">
        
            
                
                
                
                
                
                
            

        
    

Большое спасибо.

Ответы на вопрос(3)

Ваш ответ на вопрос