diff --git a/Readme.md b/Readme.md index 6420eda4..5b593934 100644 --- a/Readme.md +++ b/Readme.md @@ -536,6 +536,17 @@ Additional methods for an easier management of your scripts and cookie settings ```

+-
cookieconsent.getConfig(<field>) [v2.7.0+] +

+ + The `.getConfig()` method allows you to read configuration options from the current instance: + ```javascript + cookieconsent.getConfig('current_lang'); // get currently used language + cookieconsent.getConfig('cookie_expiration'); // get configured cookie expiration + // ... + ``` +

+
### All available options diff --git a/src/cookieconsent.js b/src/cookieconsent.js index 5c067fb0..afb092db 100644 --- a/src/cookieconsent.js +++ b/src/cookieconsent.js @@ -1375,7 +1375,7 @@ if(set){ saved_cookie_content['data'] = data; _setCookie(_config.cookie_name, JSON.stringify(saved_cookie_content)); - } + } return set; } @@ -1441,6 +1441,14 @@ return cookie[field]; } + /** + * Read current configuration value + * @returns {any} + */ + _cookieconsent.getConfig = function(field){ + return _config[field]; + } + /** * Function which will run after script load * @callback scriptLoaded @@ -1495,8 +1503,8 @@ /** * Manage dynamically loaded scripts: https://github.com/orestbida/cookieconsent/issues/101 - * If plugin has already run, call this method to enable - * the newly added scripts based on currently selected preferences + * If plugin has already run, call this method to enable + * the newly added scripts based on currently selected preferences */ _cookieconsent.updateScripts = function(){ _manageExistingScripts(); @@ -1849,4 +1857,4 @@ if(typeof window[init] !== 'function'){ window[init] = CookieConsent } -})(); \ No newline at end of file +})();