Skip to content

Instantly share code, notes, and snippets.

@jupitercow
Last active February 12, 2017 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jupitercow/721bce60317e4c87c977916244d2ecc0 to your computer and use it in GitHub Desktop.
Save jupitercow/721bce60317e4c87c977916244d2ecc0 to your computer and use it in GitHub Desktop.
Squarespace Age Gate. Add this code globally: Settings > Advanced > Code Injection. Your "Age Gate" page needs the slug of "age-gate", or you need to edit that in the code (2 places).
<script>
var cookies;
/**
* Returns the value of the cookie name.
* @param {string} name
* @returns {string}
*/
function readCookie(name,c,C,i){
if (cookies && cookies[name]) { return cookies[name]; }
c = document.cookie.split('; ');
cookies = {};
for (i = c.length-1; i >= 0; i--) {
C = c[i].split('=');
cookies[C[0]] = C[1];
}
return cookies[name];
}
/**
* Checks if the cookie
* @param {string} url
* @returns {string}
*/
function checkAge(url) {
var laChCookie = readCookie('legal');
if (!laChCookie) {
window.location.href = '/age-gate?redirect_to=' + encodeURIComponent(url);
}
return laChCookie;
}
document.addEventListener('DOMContentLoaded', function() {
if (
-1 === window.location.pathname.indexOf('age-gate')
&& -1 === window.location.pathname.indexOf('config')
&& (!window.frameElement || 'sqs-site-frame' !== window.frameElement.id)
) {
checkAge(document.URL);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment