diff --git a/Readme.md b/Readme.md index b721ecf3..d6d813d3 100644 --- a/Readme.md +++ b/Readme.md @@ -357,7 +357,7 @@ A __lightweight__ & __gdpr/ccpa compliant__ cookie consent plugin written in pla 5. Now you must configure the scripts and cookies. * [How to block/manage script tags](#how-to-blockmanage-scripts) * [How to autoclear cookies](#how-to-clear-cookies) - +
## How to block/manage scripts @@ -515,7 +515,7 @@ Cookies must be listed manually as the plugin is not aware of them. [Full example](https://github.com/orestbida/cookieconsent/blob/9ad310e7edcac7bf23600ff0e23d42254d3fced2/demo/demo_iframemanager/cookieconsent-init.js#L139).
- + ## Layout options & customization You can choose a few layout options via `gui_options`. @@ -544,7 +544,7 @@ cc.run({ You can customize the color scheme using css variables, which you can find at the top of [cookieconsent.css](src/cookieconsent.css) file.
- + ## API Once you configure and run the plugin: @@ -636,6 +636,19 @@ the following methods are available: ```

+-
cc.validConsent() +

+ + If consent is valid return true, otherwise false. + + ```javascript + // Example: show modal if consent is not valid + if (!cc.validConsent()) { + cc.show(); + } + ``` +

+
-
cc.eraseCookies(<cookie_names>, <optional_path>, <optional_domains>) [v2.5.0+]

@@ -1050,7 +1063,7 @@ CookieConsent does not have any built-in functionality to block iframes. You can } }) ``` - +

diff --git a/src/cookieconsent.js b/src/cookieconsent.js index 4ce6b65b..72046199 100644 --- a/src/cookieconsent.js +++ b/src/cookieconsent.js @@ -2131,6 +2131,10 @@ return _getCookie(cookie_name, 'one', true) !== ""; } + _cookieconsent.validConsent = function(){ + return !invalid_consent; + } + /** * Function to run when event is fired * @callback eventFired diff --git a/types/types.d.ts b/types/types.d.ts index 4c463618..267362d0 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -137,6 +137,7 @@ declare global { show(delay?: number, create_modal?: boolean): void eraseCookies(_cookies: string | string[], _path?: string, _domain?: string): void validCookie(cookie_name: string): boolean + validConsent(): boolean allowedCategory(cookie_category: string): boolean set(field: string, data: Record): boolean get(field: string, cookie_name?: string): Record