diff --git a/CHANGELOG.md b/CHANGELOG.md index b1be7bfb..dbd06dcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/nationalarchives/tna-frontend/compare/v0.3.0...HEAD) ### Added + +- The `data-tnacookiesdomain` attribute of the `` element can be used to define the domain for cookies + ### Changed - Shifted and split hero components no longer assume a contrasted background by default diff --git a/src/nationalarchives/lib/cookies.mjs b/src/nationalarchives/lib/cookies.mjs index 5b560eb3..1fe521df 100644 --- a/src/nationalarchives/lib/cookies.mjs +++ b/src/nationalarchives/lib/cookies.mjs @@ -83,7 +83,7 @@ export default class Cookies { constructor(options = {}) { const { extraPolicies = [], - domain = "", + domain = null, path = "/", secure = true, policiesKey = "cookies_policy", @@ -96,7 +96,12 @@ export default class Cookies { return window.TNAFrontendCookies; } this.extraPolicies = extraPolicies; - this.domain = domain; + if (domain === null) { + this.domain = + document.documentElement.getAttribute("data-tnacookiesdomain") || ""; + } else { + this.domain = domain; + } this.path = path; this.secure = secure; this.policiesKey = policiesKey;