Updated documentation for custom cookies

Co-authored-by: alexvoss <4134224+alexvoss@users.noreply.github.com>
This commit is contained in:
squidfunk 2023-07-24 13:00:09 +01:00
parent ea9446e6cb
commit b72adf300b
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF

View File

@ -547,8 +547,16 @@ const url ="https://polyfill.io/v3/polyfill.min.js"
### Custom cookies
If you've customized the [cookie consent] and added a `custom` cookie, the user
will be prompted to accept your custom cookie. Use [additional JavaScript] to
check whether the user accepted it:
will be prompted to accept or reject your custom cookie. Once the user accepts
or rejects the cookie consent, or [changes the settings], the page reloads[^1].
Use [additional JavaScript] to query the result:
[^1]:
We reload the page to make interop with custom cookies simpler. If Material
for MkDocs would implement a callback-based approach, the author would need
to make sure to correctly update all scripts that use cookies. Additionally,
the cookie consent is only answered initially, which is why we consider this
to be a good trade-off of DX and UX.
=== ":octicons-file-code-16: `docs/javascripts/consent.js`"
@ -556,6 +564,8 @@ check whether the user accepted it:
var consent = __md_get("__consent")
if (consent && consent.custom) {
/* The user accepted the cookie */
} else {
/* The user rejected the cookie */
}
```
@ -567,3 +577,4 @@ check whether the user accepted it:
```
[additional JavaScript]: ../customization.md#additional-javascript
[changes the settings]: #change-cookie-settings