---
updatedAt: 2025-09-17T23:29:45.000Z
agentTools:
  projectIndex: https://docs.nexiopay.com/llms.txt
---

# Adding an event listener

***

## tags: \[errors]

Errors in the payment forms can be handled by adding an event listener to the window.

For example, you can add the following script to your web page:

```javascript Example
window.addEventListener('message', function messageListener(event) {
    if (event.origin === iframeDomain) {
        if (event.data.event === 'error' || event.data.event === 'success' || event.data.event === 'processed') {
        // handle success or error messages
        }
        if (event.data.event === 'loaded') {
        //handle form loaded state
        }
        if (event.data.event === 'cardSaved') {
        //handle cardSaved
        }
        console.log(event.data.event);
    }
});
```

<br/>

# See also

* [Common errors](https://docs.nexiopay.com/docs/common-errors)
* [Handling gateway declines](https://docs.nexiopay.com/docs/handling-gateway-declines)
* [Handling security code verification failures](https://docs.nexiopay.com/docs/handling-security-code-verification-failures)