We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38359
    • 93 Posts
    Hi there,

    I've created a modal window advert that appears in the home page. I was wondering if anyone could tell me how I can set a cookie to record whether or not its been seem and then only show the pop-up if it hasn't already been seen.

    Any tips or pointers would be greatly appreciated.

    Thanks in advance!
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Fancybox, thickbox, lightbox, etc. are all javascript/css formatting bits, so inherently, they can not offer cookies at all. Really your question comes down to using PHP to set and read persistent data -- cookies are one option and sessions are another. This should revolve around a simple if statement while reading a cookie: if not set, then display the html and set the cookie, otherwise do nothing.
        • 38359
        • 93 Posts
        Hi, for anyone looking for the answer its pretty easy: simply call your javascript through a snippet thus:

        if($_SESSION['popup_seen'] != 'yes') {
        //set the session
        $_SESSION['popup_seen'] = 'yes';
        //call whatever javascript you need
        $modx->regClientStartupScript('fancybox/jquery.fancybox.pack.js');
        $modx->regClientStartupScript('fancybox/showPopUp.js');
        }