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: