简体   繁体   中英

JQuery and cookie Popup Box

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 :)

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM