Bootstrap : using cookie to show modal just once
422
MVP
I am working on another app ( just a small fun project ) will need a little php help, but thats another issue. I will post this after we solve this issue.
I fire a modal on window load, and only wish to show once. Code as is:
to add: I am using jquery.cookie.js ( https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js )
< script type="text/javascript">
$(window).load(function(){
$('#slide-bottom-modal').modal('show');
});
< /script>
with cookie i tried this, but doesnt work ( have cleared session cookies and still doesnt work )
< script type="text/javascript">
$(window).load(function(){
if($.cookie('msg') == null)
{
$('#slide-bottom-modal').modal('show');
$.cookie('msg', 'str');
}
else
{
$("#slide-bottom-modal.modal").css('display','none');
}
});
< /script>
I am not really up on cookies, so wonder if anyone can see what I am doing wrong, or if i need to define the cookie elsewhere
2
Comments
fixed ( if anyone needs solution just ask )
May you share the solution?
I need a solution @422
thirded - post it! @422
We did it using php and jQuery
< ?php if (!isset($_COOKIE['modal'])){ setcookie("modal", "true", time()+86400, "/"); ?> < script type="text/javascript"> $(window).load(function(){ $('#slide-bottom-modal').modal('show'); }); < /script> <? } ? >Oops for those who didnt spot it, our cookie is set for one day
This worked perfect for me on my video popup modal. It's set to 7 days for the cookie to expire.
<script src="/path/to/jquery.cookie.js"></script> <script> $(document).ready(function() { if ($.cookie(‘pop’) == null) { $(‘#myModal’).modal(‘show’); $.cookie(‘pop’, ’7'); } }); </script>This tutorial is for a modal popup email subscription form but uses the same principle
Bootstrap Modal Subscription Form Popup
This worked perfect for me on my video popup modal. It's set to 7 days for the cookie to expire.
<script src="/path/to/jquery.cookie.js"></script> <script> $(document).ready(function() { if ($.cookie(‘pop’) == null) { $(‘#myModal’).modal(‘show’); $.cookie(‘pop’, ’7'); } }); </script>This tutorial is for a modal popup email subscription form but uses the same principle
Bootstrap Modal Subscription Form Popup