W3cubDocs

/Web APIs

CookieStore: change event

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

A change event is fired at a CookieStore object when a change is made to any cookie.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js

cookieStore.addEventListener("change", (event) => { })

cookieStore.onchange = (event) => { }

Examples

To be informed when a cookie has changed, you can add a handler to the cookieStore instance using addEventListener(), like this:

js

cookieStore.addEventListener("change", (event) => {
  console.log("1 change event");
});

Alternatively, you can use the CookieStore.onchange event handler property to establish a handler for the change event:

js

cookieStore.onchange = (event) => {
  console.log("1 change event");
};

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
change_event 87 87 No No 73 No 87 87 No 62 No 14.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CookieStore/change_event