Modal box + checkbox + cookie

后端 未结 3 1723
北海茫月
北海茫月 2021-01-03 14:34

I would like to achieve the following:

  • On homepage load, display modal box
  • Within modal box, display a form with a single mandatory checkbox
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 15:18

    It works, finally! I was missing the callback when the cookie exists and these tics '' around the value of the cookie. Here is how it looks like. Please, let me know if there is some obvious mistake. (many thanks for your support)

    function confirm(msg,callback) {
      $('#confirm')
        .jqmShow()
        .find('p.jqmConfirmMsg')
          .html(msg)
        .end()
        .find(':submit:visible')
          .click(function(){
            if(this.value == 'Proceed'){
               $.cookie("agreed_to_terms", '1', { expires : 1, path: '/' }); //set cookie, expires in 365 days
               (typeof callback == 'string') ?
                window.location.href = callback :
                callback();
            }
            $('#confirm').jqmHide();
          });
    }
    
    
    $().ready(function() {
      $('#confirm').jqm({overlay: 88, modal: 'true', trigger: false});
    
      // trigger a confirm whenever links of class alert are pressed.
      $('a.confirm').click(function() { 
        if ($.cookie('agreed_to_terms') == '1'){window.location.href = callback =
                callback()
           //they already have cookie set
        }else{
           confirm('About to visit: '+this.href+' !',this.href); 
        }
        return false;
      });
    });// JavaScript Document
    

提交回复
热议问题