Exploit
Exploit

Reputation: 6386

How can i show the modal in the twitter bootstrap just once?

this is my code now:

<script type="text/javascript">
        $(document).ready(function() {

            if($.cookie('msg') == 0)
            {
                $('#myModal').modal('show');
                $.cookie('msg', 1);
            }

        });
</script>

on page load the model shows but when i refresh it keeps showing which it should only show once. the $.cookie is from https://github.com/carhartl/jquery-cookie

update:

this worked: the 'hide' didnt work for some reason

<script type="text/javascript">
        $(document).ready(function() {
            if($.cookie('msg') == null)
            {
                $('#myModal').modal('show');
                $.cookie('msg', 'str');
            }
            else
            {
                $("div#myModal.modal").css('display','none');
            }


        });

</script>

Upvotes: 5

Views: 6905

Answers (2)

Colin Oakes
Colin Oakes

Reputation: 354

@SarmenB 's Update worked in most browsers (FF, IE9) but not IE8.

I modified his updated solution to get it to work in IE8...

This was @SarmenB 's solution:

<script type="text/javascript">
    $(document).ready(function() {
        if($.cookie('msg') == null)
        {
            $('#myModal').modal('show');
            $.cookie('msg', 'str');
        }
        else
        {
            $("div#myModal.modal").css('display','none');
        }
    });
</script>

This is the modified solution I came up with that works is IE8 as well:

<script type="text/javascript">
    $(document).ready(function() {
        if($.cookie('msg') != null && $.cookie('msg') != "")
        {
            $("div#myModal.modal, .modal-backdrop").hide();
        }
        else
        {
            $('#myModal').modal('show');
            $.cookie('msg', 'str');
        }
    });
</script>

Basicaly to get it to work in IE8 I had to reverse what was in the if/else statements.

Upvotes: 6

Phu
Phu

Reputation: 572

From the looks of the library, the value should be a string. Try:

<script type="text/javascript">
        $(document).ready(function() {

            if($.cookie('msg') == null)
            {
                $('#myModal').modal('show');
                $.cookie('msg', '1');
            }

        });
</script>

Upvotes: 0

Related Questions