steeped
steeped

Reputation: 2633

opening Jquery dialog after destroying it

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?

Upvotes: 0

Views: 1046

Answers (3)

SpYk3HH
SpYk3HH

Reputation: 22570

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();
    }
});

Upvotes: 2

user1213320
user1213320

Reputation: 672

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

Upvotes: 0

Jan
Jan

Reputation: 5815

To stop the Youtube video:

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

from Stop a youtube video with jquery?

Upvotes: 0

Related Questions