admin管理员组

文章数量:1355535

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

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>

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./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>
Share Improve this question edited Jun 14, 2012 at 3:35 Exploit asked Jun 14, 2012 at 3:11 ExploitExploit 6,39620 gold badges72 silver badges104 bronze badges 4
  • Have you tried making the value a string? – Phu Commented Jun 14, 2012 at 3:14
  • yes, i set $.cookie('msg') != 'hide') ... then show modal then after that i set the msg cookie to a value of hide. then the modal keeps showing after refresh – Exploit Commented Jun 14, 2012 at 3:18
  • 1 Check if my solution worked. If not, can you make a jsfiddle? – Phu Commented Jun 14, 2012 at 3:20
  • your solution didnt work but what i tried is setting modal to 'hide' rather than show and saw that it didnt work either. not sure why. so what i just did is checked to see if the cookie was set and if it was manually hide with css otherwise display it. and that worked. – Exploit Commented Jun 14, 2012 at 3:34
Add a ment  | 

2 Answers 2

Reset to default 6

@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.

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>

本文标签: javascriptHow can i show the modal in the twitter bootstrap just onceStack Overflow