Consent is a cookie banner that actually holds the scripts back. The visitor picks a category, the choice is stored with a version and an expiry, and the analytics or marketing tags you marked as gated do not run until their category is allowed. One JavaScript file and one stylesheet, no dependencies, no jQuery, no build step and no network requests.
Most cookie banners only remember an answer. Consent also gates the code: any script tag you mark as gated stays inert until consent exists, then runs once. The demo page shows it live, with a panel that lists which gated scripts have actually run.
What it does
Shows a cookie banner with Accept all, Reject all and a granular preferences panel
Stores the choice in localStorage with a version and a timestamp, and asks again after a configurable number of days
Holds back gated scripts until their category is allowed
Fires a consent:change event and calls onChange after every save
Reopens from any link with a data-consent-open attribute
Offers bottom, bottom-left and centre positions
Gating scripts
Inline: a script tag with type="text/plain" and data-consent="analytics". External: the same tag with data-src instead of src, so the file is not even fetched before consent. When the category is allowed, Consent copies the tag into a fresh script element and the browser runs it. Other attributes such as async, defer and id come along. A script that has run is marked and never runs twice.
Accessible by default
The banner is a dialog: role="dialog", aria-modal, labelled by its title and described by its body text. Tab and Shift+Tab stay inside while it is open, Escape closes it when dismissal is allowed, and focus goes back to the element that opened it. Preferences are native checkboxes, and the required one is disabled so screen readers announce it correctly.
Honest limits
Consent records a choice and withholds scripts until that choice exists. That is all it does. It does not scan your site for cookies, it does not send anything to a server, it does not keep an audit trail of who agreed to what, and it does not decide what your site is legally required to show. A script that has already run stays run: withdrawing consent stops future scripts, it cannot unload code the browser has already executed.
Features
Accept all, Reject all and a granular preferences panel
Categories with a required tier that cannot be switched off
localStorage record with version, timestamp and expiry
Script gating for inline tags and for external files via data-src
consent:change event and onChange callback after every save
No dependencies, no build step, no network requests
You have to login to leave a review!
All Reviews
No Review!
What type of support is included? Verified source code Free support included Download code immediately Quality guarantee for your satisfaction Support: info@sellanycode.com
You have to purchase this item to get support!
You have to login to ask a question!
All Questions
No Question!
$25
Verified source code
Join 36136+ buyers which trust us!
Download code immediately
100% Guarantee For Item! Satisfaction guarantee policy.