Stop Video When the Popup Closes

The following custom code examples show you how to stop video play when your video popup closes.

Note: Replace the example popup ID (123) with your popup's ID number. Learn how to find the popup ID.
jQuery('#pum-123')
    .on('pumBeforeClose', function () {
        var $iframe = jQuery('iframe', jQuery(this)),
            src = $iframe.prop('src');
        $iframe.prop('src', '').prop('src', src.replace('?autoplay=1', ''));
    });

View the source on GitHub.

Follow this next YouTube code sample if you added the autoplay and mute parameters to the embed  src URL like this.

src="https://www.youtube.com/embed/s-OoG1aGYO0?start=1&autoplay=1&mute=1"

jQuery('#pum-123') 
    .on('pumBeforeClose', function () { 
        var $iframe = jQuery('iframe', jQuery(this)),
             src = $iframe.prop('src');
         $iframe.prop('src', '').prop('src', src.replace('&autoplay=1&mute=1', '')); // Remove the appended query parameters. Remove mute too if you added it before for Chrome.
     });

The code sample above removes the autoplay and mute query parameters from the existing query parameter list of the src URL.

Here's what the  src URL would look like after the jQuery code runs.

src="https://www.youtube.com/embed/s-OoG1aGYO0?start=1"

jQuery('#pum-123')
    .on('pumBeforeClose', function () {
        var $iframe = jQuery('iframe', jQuery(this)),
            src = $iframe.prop('src');
        $iframe.prop('src', '').prop('src', src.replace('&autoplay=1', ''));
    });

View the source on GitHub.

jQuery('#pum-123')
    .on('pumBeforeClose', function () {
        var $video = jQuery('video', jQuery(this));
        $video[0].pause();
    });

View the source on GitHub.

If you are new to using custom JavaScript, check out our getting started guide.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.