Show a country selection popup and save choice in Cookie
March 26, 2020
Show popup on page load
jQuery
code
<script>
$(document).ready(function(){
$("#myModal").modal('show');
});
</script>
- Save choice in cookie
code
<img src="uk.png" alt="Continue to our UK site" onclick="setCountryCookie('UK')" />
code
function setCountryCookie(country) {
document.cookie = `fppCountry=${country}`;
countrySelector.hide();
}
Redirect to the site they selected
code
window.location.href = "https://www.yoursite.com";
Set the cookie on the redirected site
pass a value in header to the new site, check for it on the other site and if present add a cookie
window.location.search
Check if cookie exists on next visit
code
"myCountry=UK; myName=Amna; myAge=31";
becomes
code
["fppCountry=UK", " myName=Amna", " myAge=31"];
code
matchString("myName is Amna", "myName"); // true
matchString("myName is Amna", "thyName"); // false