Here's the JSFiddle for what u needed JSFiddle. Here in the code you can use your own div id like you have used in your case, in the src field. Your code was missing the extra function call which would be made when we close the popup.

Here in the code, a function call is made before closing the popup as you needed. Hope this helps.

Answer from Jennis Vaishnav on Stack Overflow
🌐
Dimsemenov
dimsemenov.com › plugins › magnific-popup › documentation.html
Magnific Popup Documentation
You can define callbacks in callbacks option. Besides that, all Magnific Popup events are also dispatched using triggerHandler on target element (or to document if the element doesn’t exist).
🌐
Experts Exchange
experts-exchange.com › questions › 28279463 › Magnific-Popup.html
Solved: Magnific Popup | Experts Exchange
October 28, 2013 - <script type="text/javascript"> var hasEndBeenReached = false; $(document).ready(function() { $('.mro').magnificPopup({ delegate: 'a', type: 'image', closeBtnInside: true, tLoading: 'Loading image #%curr%...', mainClass: 'mfp-fade', gallery: { enabled: true, navigateByImgClick: true, preload: [1,6], Counter: '<span class="mfp-counter">%curr% of %total%</span>' }, image: { tError: '<a href="%url%">The image #%curr%</a> could not be loaded.', titleSrc: function(item) { return item.el.attr('title') + '<small>Maintenance, Repair and Overhaul</small>'; } }, callbacks: { change: function() { if (this.index==(this.items.length - 1) && hasEndBeenReached==false) { hasEndBeenReached = true; } if (hasEndBeenReached == true && this.index<(this.items.length - 1)) { hasEndBeenReached = false; this.close(); } } } }); }); </script>
Discussions

Magnific Popup Callback when closing
Is there anyway to get confimation when user click or trying to close the Popup. This is my demo http://jsfiddle.net/K9Geq/ If user click cancel the Popup should remain as it is, Or if user click O... More on github.com
🌐 github.com
6
June 19, 2013
Magnific Popup Callback when close
I'm creating popup using method http://dimsemenov.com/plugins/magnific-popup/documentation.html#api -> Public methods. More on stackoverflow.com
🌐 stackoverflow.com
magnific popup - $.magnificPopup.open() callbacks is not working - Stack Overflow
Did not work for me, but worked when i override close callback directly: $.magnificPopup.instance.close = function (){someAction(); $.magnificPopup.proto.close.call(this);}; 2017-05-12T09:06:19.803Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Simulating lousy conversations: Q&A with Silvio Savarese, Chief Scientist &... Interface is everything, and everything is an interface ... 2 Magnific Popup ... More on stackoverflow.com
🌐 stackoverflow.com
March 24, 2016
Magnific popup: Get current element in callback
In Magnific Popup, I want to get an attribute in the link that is clicked and use it in a callback function (using callbacks: open) to make some changes in the DOM. How can I do this? For example,... More on stackoverflow.com
🌐 stackoverflow.com
January 21, 2015
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 632
Suggestion: add an afterOpen callback · Issue #632 · dimsemenov/Magnific-Popup
February 17, 2015 - dimsemenov / Magnific-Popup Public · Notifications · You must be signed in to change notification settings · Fork 3.4k · Star 11.4k · New issueCopy link · New issueCopy link · Closed · Closed · Suggestion: add an afterOpen callback#632 · Copy link · styledev ·
Author   styledev
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 122
Magnific Popup Callback when closing · Issue #122 · dimsemenov/Magnific-Popup
June 19, 2013 - Magnific Popup Callback when ... This is my demo http://jsfiddle.net/K9Geq/ If user click cancel the Popup should remain as it is, Or if user click Ok, We need to close the Popup....
Author   mifas
Find elsewhere
🌐
CodePen
codepen.io › dimsemenov › pen › DrmzyY
Custom action before close / Confirm closing
$('#open-popup').magnificPopup({ type:'inline', callbacks: { open: function() { // this part overrides "close" method in MagnificPopup object $.magnificPopup.instance.close = function () { if (!confirm("Are you sure?")) { return; } // "proto" variable holds MagnificPopup class prototype // The above change that we did to instance is not applied to the prototype, // which allows us to call parent method: $.magnificPopup.proto.close.call(this); }; // you may override any method like so, just note that it's applied globally } } });
🌐
CodePen
codepen.io › ysnoritnk › pen › VoyJER
magnific-popup-Ajax Type-callbacks
$('.ajax-popup-link').magnificPopup({ ... could not be loaded.' }, callbacks: { parseAjax: function(mfpResponse) { mfpResponse.data = $(mfpResponse.data).find('.youtube'); }, ajaxContentAdded: ......
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 996
Callbacks don't work if a popup was opened from another popup · Issue #996 · dimsemenov/Magnific-Popup
June 24, 2017 - PROBLEM: The Login Popup is cleaned without problems, but the Sign Up Form is not cleaned, because callbacks are not triggered. ... $('#open-login-modal').magnificPopup({ items: { src: '#modal-login', type: 'inline' }, midClick: true, mainClass: 'mfp-fade', callbacks: { afterClose: function() { cleanUpForm($('#login-form')); } } });
🌐
Igem
2017.igem.org › TMMU_China › js › jquery_magnific-popup
TMMU China/js/jquery magnific-popup - 2017.igem.org
November 15, 2013 - if(data.key) { if(!mfp.popupsCache[data.key]) { mfp.popupsCache[data.key] = {}; } mfp.currTemplate = mfp.popupsCache[data.key]; } else { mfp.currTemplate = {}; } mfp.st = $.extend(true, {}, $.magnificPopup.defaults, data ); mfp.fixedContentPos = mfp.st.fixedContentPos === 'auto' ?
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 873
Callback On Init Complete · Issue #873 · dimsemenov/Magnific-Popup
June 23, 2016 - Hello, I am using a slider along with Magnific-Popup. I would like to instantiate the slider AFTER Magnific-Popup completes, but I can not seem to find any type of any event I can watch for or callback that I can use that will be fired o...
Author   jeffconklin
🌐
GitHub
gist.github.com › nekoneko-wanwan › e3b52a87b4499df7d478
magnificPopupを使ったポップアップinポップアップを実装 · GitHub
$.magnificPopup.open()でポップアップを表示している場合は、callbackにはinstanceからアクセスする · 最初のポップアップでDOMを生成しているため、.on()でliveイベントを設定 · イベントの重複登録を防ぐため、.onの前に.offを行う ·
🌐
Kriesi
kriesi.at › home › topics › enfold › alert when popup is closed
Alert when popup is closed - Support | Kriesi.at - Premium WordPress Themes
October 1, 2018 - <script type="text/javascript"> jQuery(window).load(function(){ jQuery('.open-popup-link').magnificPopup({ type:'inline', callbacks: { close: function() { alert("Popup was closed"); }, }, midClick: true }); }); </script> I followed the documentation of the magnific popup; http://dimsemenov...
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 707
Callback for prev / next Element? · Issue #707 · dimsemenov/Magnific-Popup
August 7, 2015 - I want to call a trigger a prev / next function when mfp slides an element. Therefore I tried to use the "change" callback - but the problem is that this callback also triggers when the popup gets opened, also the "direction" is set to "...
Author   uncenteredDiv
🌐
Envato Forums
forums.envato.com › envato authors › theme authors
Nested Modal using Ajax (Magnific Popup) - Envato Forums
January 10, 2017 - Hi All, Can you help me on this jquery issue I have? How do you add a nested modal using Magnific Popup? A link that shows modal inside a modal using Ajax. here’s my code below. main HTML Link One when a Link One is click it will show modal ajax… when modal shows there is a link inside, ...
🌐
Okler
okler.net › forums › topic › take-data-using-magnific-pop-up
Take data using magnific pop up – Okler Themes
$(document).on('click', '.edit-row', function(e) { e.preventDefault(); let $id = $(this).closest('tr').data('id'); let url = $(this).attr('href'); $.post( url, function( data ) { $("#id").val(data.id); $("#name").val(data.name); $("#code").val(data.code); $.magnificPopup.open({ items: { src: '#modalForm' }, type: 'inline', preloader: false, focus: '#name', modal: true, // When elemened is focused, some mobile browsers in some cases zoom in // It looks not nice, so we disable it: callbacks: { beforeOpen: function() { if($(window).width() < 700) { this.st.focus = false; } else { this.st.focus =
🌐
GeeksforGeeks
geeksforgeeks.org › jquery › how-to-use-the-magnific-popup-jquery-plugin
How to Use the Magnific Popup jQuery Plugin? - GeeksforGeeks
July 15, 2025 - The jQuery script initializes the Magnific Popup with specific settings to manage the popup's appearance and behavior.