• Hi there

    I’ve built a popup that acts as an ageGate which blocks users from entering a certain set of pages only accessible to users over the legal drinking age.

    I would like to know if it’s possible to trigger my timed cookie function when a divi close-button is clicked on my popup. Currently, it sets the cookie either way and the popup disappears when the user backs out of the page, resulting in it not actually blocking anything if you can just go back and enter the page again.

    I am not a JS expert so some of the logic just doesn’t’t add up for me when I try other code. Any help here would be greatly appreciated. Thanks

    <script>
    js
    jQuery('.verifyBtn').on('click', function(event){ 
      DiviArea.hide('verify_class'); // ← Display the Popup on button click.
      event.preventDefault();
      return true;
    })
    window.setTimeout(function(){ 
    	// First check, if localStorage is supported.
    	if (window.localStorage) {
    		// Get the expiration date of the previous popup.
    		var consentPopup = localStorage.getItem( 'nextNewsletter' );
    
    		if (consentPopup > new Date()) {
    			return;
    		}
    
    		// Store the expiration date of the current popup in localStorage.
    		var expires = new Date();
    		expires = expires.setHours(expires.getHours() + 72);
    
    		localStorage.setItem( 'nextNewsletter', expires );
    	}
    
    	DiviArea.show('#verify_class');
    }, 1000);
    </script>
    • This topic was modified 4 years, 10 months ago by sugarplum101.
    • This topic was modified 4 years, 10 months ago by sugarplum101.

    The page I need help with: [log in to see the link]

The topic ‘Popups for Divi set cookie onclick (Button)’ is closed to new replies.