Skip to content

Instantly share code, notes, and snippets.

@hmouhtar
Created June 28, 2024 21:43
Show Gist options
  • Save hmouhtar/15e1e2bf80f88735db80b9665689d096 to your computer and use it in GitHub Desktop.
Save hmouhtar/15e1e2bf80f88735db80b9665689d096 to your computer and use it in GitHub Desktop.
Elementor - Show Popup Programmatically / Disable other popups
window.addEventListener('elementor/frontend/init', function() {
var popupId = 13473;
function getReferrer() {
return document.referrer;
}
function isBot() {
var botList = ["Googlebot", "Bingbot", "Slurp", "DuckDuckBot", "Baiduspider", "YandexBot"];
var userAgent = navigator.userAgent.toLowerCase();
return botList.some(function(bot) {
return userAgent.includes(bot.toLowerCase());
});
}
function isReferrer() {
var referrer = getReferrer().toLowerCase();
return referrer.includes("example.com");
}
function triggerPopup(popupId) {
var intervalId = setInterval(function() {
try {
elementorProFrontend.modules.popup.showPopup({
id: popupId
});
clearInterval(intervalId);
} catch (error) {
console.log('Failed to show popup, retrying...', error);
}
}, 200);
}
function disableAllExceptTarget(targetId) {
var documents = elementorFrontend.documentsManager.documents;
for (var key in documents) {
if (documents.hasOwnProperty(key) && key != targetId && typeof documents[key].disable === 'function') {
documents[key].disable();
}
}
}
elementorFrontend.on('components:init', function() {
if (!isBot() && isReferrer()) {
triggerPopup(popupId);
disableAllExceptTarget(popupId);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment