Last active
February 12, 2017 20:17
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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