Popup is not opening

Hi all,

I added two popups (via templates) to my template and I want to open them by using javascript. It depends on the url of the website if the script needs to open a popup or not. So far so good…

But I can’t get the javascript to open the popup! It says that it opens it but it doesn’t. I tried different variations of code, but none of them worked for me. Also very important to mention: I set the popups to show everywhere, so that cant be the problem.

A example of code that i used:

<script>
  
  document.addEventListener('DOMContentLoaded', (event) => {
		console.log(typeof bricksOpenPopup);
    console.log('Attempting to open popup with ID 19801...');
		bricksOpenPopup('19801');
		bricksOpenPopup(19801);
    console.log('Just loaded popup');
});
  
document.addEventListener('bricks/popup/open', function(e) {
  console.log(typeof bricksOpenPopup);  
  console.log('Popup opened', e.detail);
});

  
document.addEventListener('DOMContentLoaded', (event) => {
  console.log(typeof bricksOpenPopup);  
  bricksOpenPopup('19801');
});
  
  
</script>

Hope any of you has a great idea!

Greetings,

A happy Bricks user!

A basic rule for popups not showing up. First you must apply “conditions” to the “Popup template” before running it for first time. By default, the conditions are not set on templates, and is easy to miss this step.

On the builder, while editing the template for the popup:

Settings → Template Settings → Conditions → Entire Website” (or whatever)

If Conditions is not set up, the popup template will NEVER show up.

Me, being a Bricks novice, it take me hours to find it, while testing weird scripts shared here with love, and I didn’t found this simple answer on the forum, so I shared it here.