jfeltkamp / cookiesjsr

Easily expandable cookie consent tool.
Other
22 stars 5 forks source link

Cannot tell if the new content loaded with AJAX should be blocked or not #14

Open kaszarobert opened 2 years ago

kaszarobert commented 2 years ago

Using the cookiesjsrUserConsent event, everything works fine during page load. It blocks what it needs to when not given consent. What can we do with dynamically loaded contents and AJAX updates? How can we determine if the newly loaded content should be blocked or not? Do we have to read from cookies or do we have to create a cookiesjsrUserConsent event manually?

sasa-jovanovic-sakiland commented 2 years ago

It seems we need to create event manually. Here's my example with jQuery:

// Fire a cookie's event.
let services = $.cookie('cookiesjsr');
if (services) {
  services = JSON.parse(services);
}
else {
  services = {};
}

let options = {services: services};
document.dispatchEvent(new CustomEvent("cookiesjsrUserConsent", {detail: options}));