Skip to content Skip to sidebar Skip to footer

Modal Popup Only Once Per Session

How to show this Dialog Popup one time per session, I see cookies configuration but I could not apply it to this case: $(document).ready(function() { ShowDialog(true); e.pr

Solution 1:

You can use sessionStorage (HTML 5) to keep a value that will let you know if you have already shown the popup.

http://www.w3schools.com/Html/html5_webstorage.asp

You can modify your code in this parts:

 $("#btnClose").click(function (e)
  {
     HideDialog();
     e.preventDefault();
     sessionStorage["PopupShown"] = 'yes'; //Save in the sessionStorage if the modal has been shown
  });

Then you can validate in your document.ready everytime it gets called like this:

$(document).ready(function ()
{
     if(sessionStorage["PopupShown"] != 'yes'){ 
         ShowDialog(true);
         e.preventDefault();
     }
});

This should work, let me know if you have any questions about this approach.


Post a Comment for "Modal Popup Only Once Per Session"