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
2 Answers
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
版权声明:本文标题:javascript - How can i show the modal in the twitter bootstrap just once? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744024867a2577864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论