Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Bootstrap : using cookie to show modal just once

422422 Developer MVP
edited March 2013 in Vanilla 2.0 - 2.8

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

There was an error rendering this rich post.

Comments

  • 422422 Developer MVP

    fixed ( if anyone needs solution just ask )

    There was an error rendering this rich post.

  • SrggamerSrggamer HardCore Gamer ✭✭✭

    @422 said:
    fixed ( if anyone needs solution just ask )

    May you share the solution?

  • hgtonighthgtonight ∞ · New Moderator

    I need a solution @422 :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • thirded - post it! @422

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • 422422 Developer MVP

    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>
        <?
        }
        ? >
    

    There was an error rendering this rich post.

  • 422422 Developer MVP

    Oops for those who didnt spot it, our cookie is set for one day

    There was an error rendering this rich post.

  • 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

Sign In or Register to comment.