Want your Popup widget to close automatically after a set amount of time? Our developers have created a custom solution just for that
const DISPLAY_DURATION_MS = 8000;
const WIDGET_ID = 'YOUR_WIDGET_ID';
const waitForElem = (selector) =>
new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(() => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});
waitForElem(`[class*="${WIDGET_ID}"] [class*="Popup__PopupContent-sc"]`).then(
(popup) => {
setTimeout(() => {
popup.querySelector('[class*="PopupCloseControlContainer-sc"]')?.click();
}, DISPLAY_DURATION_MS);
}
);
In the 1st line of the code, you should set the display duration in milliseconds. In the 2nd line, please replace YOUR_WIDGET_ID
with the ID of your widget.
Once this done, add the resulted code to the Custom JS field on the Settings tab of your widget’s settings.
Guys, was this solution helpful to you? Let us know in the comments