I used John Snyder's application: All The Things That Pop Up for help on getting my dialog page to get a handle on the ‘top level APEX page’ so I can implement a Warn on Close message when changes has been made to a modal, and the user cancels a dialog via
This is demonstrated in my application (AF_PLAYS | demo | demo_123) on page 9 (Warn before Closing Modal) by editing a customer row, making a change and closing the page without saving in one of the above ways.
This will open a modal page (p11) with which gets a handle on the top level APEX page as follows:
var theDialog$ = apex.util.getTopApex().jQuery(".ui-dialog-content").filter(function() { return $(this).find("iframe")[0].contentDocument.body === document.body; });
This works well as long as there is only the one dialog page being called from page 9

However, as demonstrated on page 10 (Warn before Closing: Multiple Modals) which also has a Inline Popup dialog, when calling the same modal page (p11) it throws a Javascript error:
TypeError: Cannot read properties of undefined (reading 'contentDocument')
I think this is because there is more than the one dialog with class ui-dialog-content
and therefore multiple “iframes” on the parent page: #user_pop and #apex_dialog_1

I have tried changing the statements and although I don't get the JS error anymore it's still not getting the parent page:
var theDialog$ = apex.util.getTopApex().jQuery("apex_dialog_1.ui-dialog-content") …
var theDialog$ = apex.util.getTopApex().jQuery("ui-dialog-content.ui-widget-content.js-dialogReady") …
var theDialog$ = apex.util.getTopApex().jQuery(".ui-dialog-content").filter(function() { return $(this).find("iframe")[1] …
Any help on understanding how I would do this, would be appreciated!
Thanks
Annelize