Reputation: 1079
I'm working on a site that has TWO home pages (different langauges). Each homepage displays a pop up modal in the homepage language when the user gets to the site. As of now it's working when the user first goes to the "English" page and THEN goes to the "French" page but if the user is first sent to the French page BOTH modals are showing. How can I assure only the given language modal will show on each page? I am using Jquery to achieve this.
URL's / page: index.html - English, index-fr.html - French
JQuery:
window.setTimeout(function () {
var url = location.pathname;
if (
url.indexOf("index") > -1 &&
!disableWelcomeModal &&
_siteNS.Utils.readCookie("modal_english") !== "accepted"
) {
openPopUpModal($modalEnglish);
var expiration = new Date();
var timeCurrent = expiration.getTime();
var oneHour = timeCurrent + 3600 * 1000;
expiration.setTime(oneHour);
_siteNS.Utils.setCookieCustomDuration(
"modal_english",
"accepted",
expiration.toUTCString()
);
}
if (
url.indexOf("index-fr") > -1 &&
_siteNS.Utils.readCookie("modal_french") !== "accepted"
) {
openPopUpModal($modalPopUpFrench);
var expiration = new Date();
var timeCurrent = expiration.getTime();
var oneHour = timeCurrent + 3600 * 1000;
expiration.setTime(oneHour);
_siteNS.Utils.setCookieCustomDuration(
"modal_french",
"accepted",
expiration.toUTCString()
);
}
}, 4000);
Upvotes: 1
Views: 45
Reputation: 11416
It should work if you adjust your first if
clause like this:
if (
url.indexOf("index") > -1 &&
url.indexOf("index-fr") == -1 &&
!disableWelcomeModal &&
_siteNS.Utils.readCookie("modal_english") !== "accepted"
)
Upvotes: 2