"Modal with jQuery Cookie"
Bootstrap 3.1.0 Snippet by calvin52019

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!-- Referances jQuery Cookie : https://github.com/carhartl/jquery-cookie Modal : http://getbootstrap.com/javascript/#modals --> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <div class="container"> <div class="row"> <div class='modal fade' id='myModal'> <div class='modal-dialog'> <div class='modal-content'> <div class='modal-header'> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class='modal-title'> <strong>MODAL WITH JQUERY COOKIE</strong> </h4> </div> <!-- / modal-header --> <div class='modal-body'> <img class="img-responsive" src="http://placehold.it/600x350&text=MODAL" /> </div> <!-- / modal-body --> <div class='modal-footer'> <div class="checkbox pull-right"> <!--label> <input class='modal-check' name='modal-check' type="checkbox"> Don't Show </label--> <div class="onoffswitch"> <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox modal-check" id="myonoffswitch" checked> <label class="onoffswitch-label" for="myonoffswitch"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span> </label> </div> </div> <!--/ checkbox --> </div> <!--/ modal-footer --> </div> <!-- / modal-content --> </div> <!--/ modal-dialog --> </div> <!-- / modal --> </div> <!-- / row --> </div> <!-- / container -->
.onoffswitch { position: relative; width: 90px; -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none; } .onoffswitch-checkbox { display: none; } .onoffswitch-label { display: block; overflow: hidden; cursor: pointer; border: 2px solid #999999; border-radius: 0px; } .onoffswitch-inner { display: block; width: 200%; margin-left: -100%; transition: margin 0.3s ease-in 0s; } .onoffswitch-inner:before, .onoffswitch-inner:after { display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 26px; font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold; box-sizing: border-box; border: 2px solid transparent; background-clip: padding-box; } .onoffswitch-inner:before { content: ""; padding-left: 10px; background-color: #2E8DEF; color: #FFFFFF; } .onoffswitch-inner:after { content: ""; padding-right: 10px; background-color: #CCCCCC; color: #333333; text-align: right; } .onoffswitch-switch { display: block; width: 25px; margin: 0px; background: #000000; position: absolute; top: 0; bottom: 0; right: 65px; transition: all 0.3s ease-in 0s; } .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner { margin-left: 0; } .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch { right: 0px; }
$(document).ready(function(){ //Referances //jQuery Cookie : https://github.com/carhartl/jquery-cookie //Modal : http://getbootstrap.com/javascript/#modals var my_cookie = $.cookie($('.modal-check').attr('name')); if (my_cookie && my_cookie == "true") { $(this).prop('checked', my_cookie); console.log('checked checkbox'); } else{ $('#myModal').modal('show'); console.log('uncheck checkbox'); } $(".modal-check").change(function() { $.cookie($(this).attr("name"), $(this).prop('checked'), { path: '/', expires: 1 }); }); });

Related: See More


Questions / Comments: