Setting an extra cookie and using it to control the consent form #4674
-
I'm trying to get cookie consent to be shared across docs and our main website. Our main website sets a cookie, I've managed to get it to work from docs -> website. In other words, when a user accepts cookies on the docs website, it also sets the I've almost got it working the other way, but not quite. I get this behaviour: accept cookies on main website -> go to docs website -> consent banner displays -> refresh docs page (don't click anything, just refresh) -> consent banner now doesn't display My best guess at the problem is that the consent banner code runs & displays before my extra JS has had a chance to read the Relevant Material code: https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/javascripts/consent.html My code is here: https://github.com/n8n-io/n8n-docs/blob/main/docs/_extra/javascript/extra.js Before I started writing my own JS for this, I did try simply renaming the cookie, as described here. But this didn't seem to do anything. Material's consent seems to be stored in local storage, rather than in a cookie. So: anyone know a way to get extra JS to run before Material's own? Or some other approach to ensure the consent banner is hidden? Any advice appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, Material for MkDocs' cookie consent form is not really setting cookies but uses local storage. Your use case is a little exotic, which is why theme extension might be your best option. You could override the Lines 359 to 371 in 91bc63c |
Beta Was this translation helpful? Give feedback.
Yes, Material for MkDocs' cookie consent form is not really setting cookies but uses local storage. Your use case is a little exotic, which is why theme extension might be your best option. You could override the
javascripts/consent
partial and apply your logic before the theme's logic runs. Extra JavaScript will always run after the theme's logic. The consent logic is here (bottom):mkdocs-material/src/base.html
Lines 359 to 371 in 91bc63c