Guides
JavaScript API
Control the Consentful banner from your own code — open preferences, read or change consent, and listen for changes.
Consentful exposes window.CookieConsent once it has loaded.
| Method | What it does |
|---|---|
CookieConsent.getState() | The visitor's current choice, or null if they haven't chosen. |
CookieConsent.acceptAll() | Allow every category. |
CookieConsent.rejectAll() | Allow only strictly necessary. |
CookieConsent.accept(['analytics']) | Allow exactly these categories (plus necessary). |
CookieConsent.openPreferences() | Open the preference center. |
CookieConsent.withdraw() | Forget the choice; the banner shows again. |
CookieConsent.downloadReceipt() | Download the visitor's consent receipt. |
Examples
A "Cookie settings" link in your footer:
Run code when consent changes:
