I obviously don’t want the modal to appear each and every time but just once. If the user fills out the form the modal shouldn’t appear for lets say a year, when the user dismisses the modal shouldn appear for lets say 1/2 a year. How can I accomplish this?
For now I have added just a cookie for 1/2 a year:
That is working ok but I have an aditional question. What I would like to realize is that if a user has filled out the form for receiving the newsletter he or she will be presented with another modal with a special offer (at least if a special offer is available) But this should happen in a subsequent session (not in the same session). What would be the best way to accomplish that?
I’m the kind of user that when a modal asking me to subscribe to anything (free or otherwise) pops in, I right-click it and block it.
Cookies are imperfect. No matter what you do, cookies disappear. Sometimes intentionally, sometimes accidentally.
m_hutley’s suggestion to use localstorage is a much better solution, but also not perfect. localstorage is dependent upon browser history, and if a user clears browser history on exit or uses incognito mode the localstorage will clear.
If your site does not require a login, there are not any perfect solutions, really. On the flip side, if users logon to your site, you can use a database to keep track of things like this.
@WolfShade. I know that as well. But that are the requirements. Offcourse a login suuation would be way easier to deal with, but like I said in the OP this is about subscribing to a newsletter, so some data is available from those subscribers. When just using Cookies what would be the best approach? Even if they are imperfect
@m_hutley nailed it. You set the cookie when the form has been submitted (I assume you’re using AJaX for the submit) and the server returns a successful process. *
^ _ ^
*Successful process: I set the first five characters of what is being returned to "YES: " or "ERR: " and use that in determining what message will be displayed to the user, and other processing. I use a switch case statement.
var errYes = data.split(': '), message = data.split(': ');
//error stuff here
//successful stuff here
@WolfShade: Yes I am using AJAX for submit, actually it is a 2 step process. First they subscribe after which they receice an email with a link to confirm the subscription. So I should indeed set the Cookie for newsletterModal in the second Ajax success call. But then? This is where I get stucked. I only want to show that second modal to people that have signed up. I realy have no clue where to start or end
I’m assuming that the link opens your site in a browser and presents this second modal? Does clicking the link confirm subscription? Or does the second modal contain a button to click for confirming the subscription?
If the former (click confirms), then as soon as the second modal appears that’s when you set the cookie.
If the latter (modal button confirms), then as soon as the button is clicked you set the second cookie.
Both instances would be a completely new function.