What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    My Lightbox Opens Automatically on Every Visit to My Web Page. How Can I Get It to Do so Only Once per Browser Session?

    Asked by WideScenes on April 03, 2015 at 10:39 PM

    Hi , I tried the code as per instructions, however still appears each time page is refreshed within same browser session. can you my page to see if correct? http://www.widescenes.com/Fiji2015.html

    thanks



    This is a re-post of a comment on Using cookies to auto-open a lightbox form per browser session

  • Profile Image

    Answered by raul on April 03, 2015 at 10:52 PM

    You're using an HTML page instead of a PHP page and this is why the code is not executed.

    Try to change the extension of your file to .php so it's named as Fiji2015.php. if your hosting provider supports PHP and you've enabled it in your site. Then the lightbox script should be executed only one time.

  • Profile Image

    Answered by WideScenes on April 03, 2015 at 11:06 PM

    Thanks for your help, will give it a try.  Is there any code that I can use for HTML page that does the same thing?

  • Profile Image

    Answered by Ben on April 04, 2015 at 05:12 AM

    Unfortunately server side cookies are only available on the PHP side, but you could do the same with the javascript cookies.

    When we change the code from above it would go from this:

    <?php
    $showlightbox="0";
    if(!isset($_COOKIE['beenhere'])) {
     // FIRST VISIT TO WEBPAGE THIS SESSION
     setcookie("beenhere", '1');
     $showlightbox="1";
    }
    ?>

    to this:

    <script type="text/javascript">
       var cookieBeenHere = getCookie('jotformBeenHere');
       document.cookie="jotformShowLightBox=0";

    if(cookieBeenHere && (cookieBeenHere ==1 || cookieBeenHere == "1") ) {
       document.cookie="jotformBeenHere=1";
       document.cookie="jotformShowLightBox=1";
    }

    /* function taken from the page above */
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1);
            if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
        }
        return "";
    }
    </script>

    Do let us know how it works for you.

  • Profile Image

    Answered by WideScenes on April 04, 2015 at 05:41 AM

    Thanks Ben,

    Assume I would still keep the original jotform lightbox code as well.  If so have replaced the php code with above and still get the lightbox appearing each time I refresh the page within the same browser session.  Maybe I am making a mistake with the code.

  • Profile Image
    JotForm Support

    Answered by abajan on April 04, 2015 at 10:43 AM

    @WideScenes

    When I view the source of your web page I'm seeing the PHP script, not the JavaScript one. Here's a screenshot of your page's source:

    It can't be a caching issue with my browser because this is the first time I'm visiting that page. Please ensure that you're saving the change correctly.

    Do let us know how it turns out.

    Thanks

  • Profile Image

    Answered by WideScenes on April 04, 2015 at 09:20 PM

    Hi Abajan, 

     

    Was testing locally, have now uploaded to site, so you can view page with html code.  Let us know if there is a problem in how I have added the code.

     

    Thanks so much for your help.

  • Profile Image
    JotForm Support

    Answered by Welvin on April 05, 2015 at 08:33 AM

    Unfortunately, it's not working. Will check this and get back to you later today.

    Thank you!

  • Profile Image
    JotForm Support

    Answered by abajan on April 05, 2015 at 10:55 PM

    While our colleague Welvin works on a cookie solution, here's one which uses an HTML5 feature called Session Storage. Even though the doctype of your page is XHTML 1.0 Transitional and not HTML5, my tests indicate that it will still work.

    Thanks 

  • Profile Image

    Answered by Diego Gonzalez  on May 11, 2015 at 07:33 PM

    I am using this:

    <?php

    $showlightbox="0";

    if(!isset($_COOKIE['beenhere'])) { 

    // FIRST VISIT TO WEBPAGE THIS SESSION

        setcookie("beenhere", '1', time()+ 10800,"/","mydomain.com");

    $showlightbox="1";

    }

     

    ?>

     

    <?php

    if ($showlightbox) { ?>

     

    <script>

          function openColorBox(){

            $.colorbox({iframe:true, width:"880px", height:"710px", href: "http://mydomain,com/myiframe/"});

          }

          

          function countDown(){

            seconds--

            $("#seconds").text(seconds);

            if (seconds === 0){

              openColorBox();

              clearInterval(i);

            }

          }

     

          var seconds = 1,

              i = setInterval(countDown, 1000);

        </script>

     

    <?php  } ?>

     

    It works at the firs time, then if I went to another section of the webpage and press BACK BUTTON the script shows me again the iframe in the lightbox, If I refresh again the script stops. So the issue is just when I press the Back Button in Firefo, IE and Chrome.

    Regards

  • Profile Image
    JotForm Support

    Answered by Kiran on May 12, 2015 at 12:26 AM

    Hello Diego,

    Your query is moved to a separate thread and shall be addressed there shortly.

    http://www.jotform.com/answers/568125

    Thanks!