CookieStore: change event
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{securecontext_header}}{{APIRef("Cookie Store API")}}
A change event is fired at a {{domxref("CookieStore")}} object when a change is made to any cookie.
Syntax
Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:
addEventListener("change", (event) => { })Alternatively, assign to the event handler property of the interface:
onchange = (event) => { }Event type
A {{domxref("CookieChangeEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("CookieChangeEvent")}}
Examples
To be informed when a cookie has changed, you can add a handler to the cookieStore instance using {{domxref("EventTarget.addEventListener", "addEventListener()")}}, like this:
cookieStore.addEventListener("change", (event) => {
console.log("1 change event");
});Alternatively, you can use the onchange event handler property to establish a handler for the change event (but note that this replaces other event listeners added using onchange, if any):
cookieStore.onchange = (event) => {
console.log("1 change event");
};Specifications
{{Specifications}}
Browser compatibility
{{Compat}}