Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
Hello , i am using bootstrap modalpopup to show my advertisement on pageload. However, i only want the modalpopup to be shown only once during the session and will not appear anymore after the user close the modalpopup.

I have tried the following codes but the modalpopup keeps appearing after page refresh :

<script type="text/javascript">
$(window).load(function () {
$('#myModal').modal('show');
});
</script>

This codes shows the modalpopup everytime the page refresh. Any idea how to make it appear only once within a session only?

Any help would be greatly appreciated!
Posted
Updated 10-Mar-16 23:12pm
Comments
Jameel VM 23-Jul-13 8:42am    
remove it from the onload function. show the pop up only you want.
Jerrell77 24-Jul-13 9:59am    
but if i refresh that particular page, it will show up again. how do you make it such that it only comes up once? and not appear after you close it anymore

you can use this:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script type="text/javascript">
C#
$(function () {
       var overlay = $('<div id="overlay"></div>');
       overlay.show();
       overlay.appendTo(document.body);
       $('.popup').show();
       $('.x').click(function () {
           $('.popup').hide();
           overlay.appendTo(document.body).remove();
           return false;
       });
   });


</script>
CSS
#overlay
{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    filter: alpha(opacity=70);
    -moz-opacity: 0.7;
    -khtml-opacity: 0.7;
    opacity: 0.7;
    z-index: 100;
    display: none;
}
.cnt223 a
{
    text-decoration: none;
}
.popup
{
    width: 100%;
    margin: 0 auto;
    display: none;
    position: fixed;
    z-index: 101;
}
.cnt223
{
    min-width: 600px;
    width: 600px;
    min-height: 150px;
    margin: -100px 100px 100px 55px;
    background: #f3f3f3;
    position: relative;
    z-index: 103;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 5px #000;
}
.cnt223 .x
{
    float: right;
    height: 35px;
    left: 22px;
    position: relative;
    top: -25px;
    width: 34px;
}
.cnt223 .x:hover
{
    cursor: pointer;
}



XML
<div class='popup'>
    <div class='cnt223'>
        <asp:ImageButton ID="ImageButton1" ImageUrl="~/HR/Controls/images/x.png" runat="server"
            class='x' />

            ///Your coding will go here.            

        </div>
</div>




it will you external resource for jquery from internet. if you want to use it offline you can download and use it inside src.


Hope this will help you.
 
Share this answer
 
Comments
Jerrell77 23-Jul-13 10:16am    
okay thanks!
ShivKrSingh 24-Jul-13 8:09am    
is that what you was asking for.....
Jerrell77 24-Jul-13 9:58am    
not really. what i really want is to be able to hide the modalpopup after closing it and not making it appear anymore. i tried your codes but is not what i wanted. the modalpopup keeps popping up after i refresh the page but i only want it to pop up the first time only.
ShivKrSingh 25-Jul-13 5:22am    
you can do one thing that take one button and make its visible hide. and on click of this open this popup like

in page load
if(!isPostback)
{
btnName_Click(sender, e);
}
so this code will make is click only first time. on after this even after Post back. It will only show when you are visiting your page first time. One More thing if you will Manually Refresh page that will act as it is loading first time. so it will show popup again but not after it. Hope this will fulfill your requirement.


<update panel>
<content template>
 
//put Popup control here
 
</content template>
</update panel>




Try this.....
 
Share this answer
 
v2
Comments
Jerrell77 23-Jul-13 23:43pm    
the modalpopup keeps showing after page refresh. can't be solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900