mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Updated documentation for custom cookies
Co-authored-by: alexvoss <4134224+alexvoss@users.noreply.github.com>
This commit is contained in:
parent
ea9446e6cb
commit
b72adf300b
@ -547,8 +547,16 @@ const url ="https://polyfill.io/v3/polyfill.min.js"
|
|||||||
### Custom cookies
|
### Custom cookies
|
||||||
|
|
||||||
If you've customized the [cookie consent] and added a `custom` cookie, the user
|
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
|
will be prompted to accept or reject your custom cookie. Once the user accepts
|
||||||
check whether the user accepted it:
|
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`"
|
=== ":octicons-file-code-16: `docs/javascripts/consent.js`"
|
||||||
|
|
||||||
@ -556,6 +564,8 @@ check whether the user accepted it:
|
|||||||
var consent = __md_get("__consent")
|
var consent = __md_get("__consent")
|
||||||
if (consent && consent.custom) {
|
if (consent && consent.custom) {
|
||||||
/* The user accepted the cookie */
|
/* 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
|
[additional JavaScript]: ../customization.md#additional-javascript
|
||||||
|
[changes the settings]: #change-cookie-settings
|
||||||
|
Loading…
Reference in New Issue
Block a user