---
title: WindowEventHandlers.onmessage
slug: Web/API/WindowEventHandlers/onmessage
tags:
  - API
  - Event Handler
  - HTML-DOM
  - Property
  - Reference
  - Window
  - WindowEventHandlers
  - events
  - onmessage
browser-compat: api.WindowEventHandlers.onmessage
---
{{APIRef("HTML DOM")}}{{ SeeCompatTable() }}

The **`onmessage`** property of the
{{domxref("WindowEventHandlers")}} mixin is the [event handler](/en-US/docs/Web/Events/Event_handlers) called
whenever an object receives a {{event("message")}} event.

## Syntax

```js
window.addEventListener('message', function(event) { /* ... */ })
window.onmessage = function(event) { /* ... */ }
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
