0

I have a youtube video appear in the jquery dialog box, so if it is playing while the dialog window is closed, it will remain playing behind the scenes.

What I do as a result is destroy the window when it is closed:

    $("#gallery_reel").dialog({
            autoOpen: false,
            width: 540,
            close: function() {
                $(this).dialog('destroy');
            }
    });

But once the dialog box is destroyed, it won't open again unless I refresh the page. How do I reopen the dialog box?

steeped
  • 2,613
  • 5
  • 27
  • 43
  • 1
    You can just close it and not destroy `.dialog('close')` – Mike Park Oct 23 '12 at 17:22
  • when I close it, the video is still playing in the background. – steeped Oct 23 '12 at 17:23
  • 1
    @steeped looks like you need to know how to stop the video from playing before closing the dialog, then. Are you using a video player API? Or just HTML5 video? Destroy is not a good method, because, in order to open the object you'll have to reinstantiate it, which causes a fair amount of unnecessary overhead. – Ohgodwhy Oct 23 '12 at 17:25
  • Possible duplicate of http://stackoverflow.com/questions/2128535/stop-a-youtube-video-with-jquery – Jan Oct 23 '12 at 17:26
  • Why not use the close function callback to just stop the youtube video? – SpYk3HH Oct 23 '12 at 17:26
  • @SpYk3HH how do I callback the video? – steeped Oct 23 '12 at 17:35
  • stop the video then use `.detach()`. see if this can help you: http://jsfiddle.net/RASG/ppDat/ – RASG Oct 23 '12 at 17:57

3 Answers3

2

I would SUGGEST just using the close function to STOP the youtube video, but if you insist on other, instead of destroy try the following:

Non-preferred (will copy html into a newly emptied dialog)

$("#gallery_reel").dialog({
    autoOpen: false,
    width: 540,
    close: function() {
        var inrHTML = $(this).html();
        $(this).empty().html(inrHTML);
    }
});

Should be better Method (Based on the thought that most "embeded youtube" vids are in Iframes, i think

$("#gallery_reel").dialog({
    autoOpen: false,
    width: 540,
    close: function() {
        $(this).find("iframe").get(0).stopVideo();
    }
});
Community
  • 1
  • 1
SpYk3HH
  • 22,272
  • 11
  • 70
  • 81
  • the close function does not stop the youtube video. – steeped Oct 23 '12 at 17:34
  • No but this should inevitably remove the original HTML inside your dialog and replace it with a copy of the original html, thus the video should be stopped, so to speak – SpYk3HH Oct 23 '12 at 17:38
0

To stop the Youtube video:

$('#playerID').get(0).stopVideo();

from Stop a youtube video with jquery?

Community
  • 1
  • 1
Jan
  • 5,688
  • 3
  • 27
  • 44
0

this is because when you "destroy" you pop the mapped var off of the jQuery stack.

varname = new $("#gallery_reel").dialog(.....); 

would pop it back onto the stack

Question here is do you need to destroy or just close the dialog.

proper use of variables and a cleanup when they leave the page instead of closing the dialog could fix this

user1213320
  • 650
  • 1
  • 6
  • 13