Close popup when click button

Is it possible to auto close the popup when you click the button that you have add on the blocks?

1 Like

Hi @Giorgos :wave:

Could you please send me a direct link to the page where your widget is installed? I’ll be happy to look into this for you :slightly_smiling_face:

Hi @Max you can check here popup There are 2 sections A & B. The popup button “GO TO B” have an anchor for section B. When you click the button, the page goes to section B but the popup still remains visible. Is it possible when you click the button and move to section B, the popup to close automatically?

1 Like

Got you!

I’ll discuss it with devs and get back to you a bit later :slightly_smiling_face:

1 Like

Hi @Max is there any update?

1 Like

@Giorgos Please accept my deepest apologies for the delayed reply!

We’ve added this code to the Custom JS field on the Settings tab of your widget’s settings:

const waitForElement = (selector, root = document) => new Promise(res => {
  let i = 0;

  const check = () => {
    const component = root.querySelector(selector);
    if (component) {
      res(component);
    } else if (i !== 50) {
      setTimeout(check, 100);
      i++;
    }
  };

  check();
});

waitForElement(".eapps-popup-2f0ef511-0ee1-4b3a-8cd4-6b05f8eff1ba-custom-css-root [class*='Popup__PopupContainer-sc']").then(popup => {
  const [closeBtn, btn] = popup.querySelectorAll("button");
  btn.addEventListener("click", () => closeBtn.click());
});

Please check it out and let me know if it worked :slightly_smiling_face:

1 Like

Hi @Max @Helga
what kind of ID is that?
The Widget ID from Popup or something?

what do I plan to do?
Multistep in a Popup ist not possible, what do I plan to do?
A Button in a Popup open another popup. That works, but the first popup must also close on this click.
I think this JS Code is a solution.

1 Like

@Sina Giorgos had a button on his website redirecting to another section of the same page on click. And this code helps to automatically close the popup when redirecting to another section.

I’d be happy to find a solution for your specific case as well. Could you just share a link to page with your widget and describe what you’d like to achieve?

@Max

with this Solution I can open the first popup - works

HTML Element ID for Button to open a Popup on click

Now I want to open another popup with this popup with another button - it also works.

If the second popup is open, then the first one is still open in the background. It’s about closing this at the same time.

With this I created a multistep popup.

Unfortunately that doesn’t work.

1. Popup

The Button in the first Popup which opens the 2nd popup and should now close the 1st popup

2. Popup

I haven’t created the button that opens the first popup yet.

1 Like

Sorry for being not clear enough! Could you please send me a direct link to the page where these Popup widgets are installed?