🚀 Stop Losing Visitors — Turn Traffic into Revenue with Popup Maker Pro →

Get Started
View Categories

Stop Video When the Popup Closes

If you embed a video to a Popup Maker popup using Popup Maker Lite (free version), you need an extra step. You’ll need to make sure the audio stops playing when you close the popup.

The following custom code examples show you how to stop your YouTube, Vimeo, and HTML5 video playing when your video popup closes.

Note: If you use any of these code snippets, replace the example popup ID (123) with your popup’s ID number. Learn how to find the popup ID.

YouTube (no other query parameters in the src URL)

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.

YouTube (if already other query parameters in the src URL)

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"

Vimeo

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.

HTML5

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 in WordPress, check out our getting started guide.

Leave the first comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.