JQuery and cookie Popup Box

1.4k views Asked by At

I have a popup that shows a form. I only want it to show up once when the user first enters site, then after don't show again. The code below isn't working, without cookie and if the popup works.

  <script language="javascript" type="text/javascript">
        window.onload=function(){
            if(jQuery.cookie("popup") != "false"){
                jQuery("#subscribePop").bPopup({
                    modal: true
                });
                jQuery.cookie("popup","false");
                return false
            }
        }
    </script>

I still cant get this working with this code no errors or nothing. Is there even another way to do this thats better, just want div to show once when they enter then not to show again after its closed for that user

Is this the best way? I'm open to other suggestions :)

1

There are 1 answers

1
aki On
<script type="text/javascript">
    jQuery(document).ready(function($){
        if (!$.cookie("popup")) {
            //trigger your popup message
           $("#subscribePop").trigger('create'); //or whatever command you have for pop-ing it
            //after pop-up show, rewrite the cookie
           $.cookie("popup","false"); //not to show again
        }
        else
        {
           $("#subscribePop").trigger('destroy'); //or whatever
        }
    });
</script>

Hope it helps one way or another