Close Parent Frame Modals from Iframe

Hi There,

On my page, I have an iframe within a modal within a modal.

Parent Frame

Parent Modal

Child Modal

Iframe

I have found on the forum a way of making a button that closes all of my modals, so it would act as a “home” button of sorts. This is the snippet I am using (in the parent frame).

jQuery('.closemodal').on('click', function() {
    jQuery('#custom-home-button-modal .x-modal-close').trigger('click');
    return false;
});

However, I would like to be able to trigger this on the parent frame with two methods from inside the iframe.

Method 1. onclick of a button in iframe
Method 2. after 3 seconds of the page loading

I’ll leave a secure note below with the relevant pages and credentials.

Appreciate any help you’re able to give - I’ve been googling for days and coming up trumps.

Thank you

Hi @el3ctrofuzz,

Thanks for reaching out.
It is not very clear what exactly you are trying to do here. Can you please elaborate a bit more? If you are trying to close all the modals on a button click, you need to point to the x-modal-close selector like the following example code.

jQuery('.closemodal').on('click', function() 
{
    jQuery('.x-modal-close').trigger('click');
    return false;
});

Please remember that the above code will work if copied as it is and don’t conflict with any existing style.
Please note that the code provided serves only as a guide to help you get started custom coding on your own if there’s no option offered in our theme or the products we bundle.
We really do not provide support for custom codes that means we can’t fix it in case it conflicts with something on your site nor will we enhance it.

Thanks

Hey @tristup, thanks for the quick reply.

I do already have that snippet working on the parent page, but that’s not quite my concern. I will explain again :slight_smile:

In the parent frame/ page, I have a modal. Within this modal, an iframe.

From the iframe, I want to 1. click a button to close the parent frame’s modals, and 2. after 3 secs, automatically close the parent frame’s modals.

Please are you able to help?

Hi @el3ctrofuzz,

Unfortunately, it is not possible to close the modal from one child iframe to parent iframe.

Thanks

Hi @tristup,

Thanks for the reply. Just to clarify, I’m not talking iframe to iframe, I’m talking about an iframe within a parent frame (i.e. a web page) - not a parent iframe.

I believe that it is possible, I just lack the JS knowledge. I’m under the impression that if the function could be named on the parent frame/page, then the iframe could call it.

Hi @el3ctrofuzz,

If that is the case, you may need an extensive custom JavaScript which is beyond the scope of Theme Support. I would like to suggest you hire a developer who can assist you to do the customization or you can avail of our newly launched service called One, where we answer the questions beyond normal theme support.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.