Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt CookieStore change event to new structure #12913

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7486,6 +7486,7 @@
/en-US/docs/Web/API/Constraint_validation/invalid_event /en-US/docs/Web/API/HTMLInputElement/invalid_event
/en-US/docs/Web/API/ConvolverNode.buffer /en-US/docs/Web/API/ConvolverNode/buffer
/en-US/docs/Web/API/ConvolverNode.normalize /en-US/docs/Web/API/ConvolverNode/normalize
/en-US/docs/Web/API/CookieStore/onchange /en-US/docs/Web/API/CookieStore/change_event
/en-US/docs/Web/API/Coordinates /en-US/docs/Web/API/GeolocationCoordinates
/en-US/docs/Web/API/Coordinates.accuracy /en-US/docs/Web/API/GeolocationCoordinates/accuracy
/en-US/docs/Web/API/Coordinates.altitude /en-US/docs/Web/API/GeolocationCoordinates/altitude
Expand Down
51 changes: 51 additions & 0 deletions files/en-us/web/api/cookiestore/change_event/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: 'CookieStore: change event'
slug: Web/API/CookieStore/change_event
tags:
- API
- Reference
- Event
- change
- onchange
- CookieStore
browser-compat: api.CookieStore.change_event
---
{{securecontext_header}}{{DefaultAPISidebar("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 methods like {{domxref("EventTarget.addEventListener", "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 {{domxref("EventTarget.addEventListener", "addEventListener()")}}, like this:

```js
cookieStore.addEventListener('change', function(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 = function(event) {
console.log('1 change event');
};
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
12 changes: 5 additions & 7 deletions files/en-us/web/api/cookiestore/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ The `CookieStore` is accessed via attributes in the global scope in a {{domxref(

{{InheritanceDiagram}}

## Properties

### Event handlers

- {{domxref("CookieStore.onChange")}}
- : The `onchange` EventHandler is called whenever a cookie is changed.

## Methods

- {{domxref("CookieStore.delete()")}}
Expand All @@ -34,6 +27,11 @@ The `CookieStore` is accessed via attributes in the global scope in a {{domxref(
- {{domxref("CookieStore.set()")}}
- : The `set()` method sets a cookie with the given name and value or options object, it returns a {{jsxref("Promise")}} that resolves when the cookie is set.

## Events

- {{domxref("CookieStore.change_event")}}
- : The `change` event fires when a change is made to any cookie.

## Examples

In this example we set a cookie and write to the console feedback as to whether the operation succeeded or failed.
Expand Down
47 changes: 0 additions & 47 deletions files/en-us/web/api/cookiestore/onchange/index.md

This file was deleted.