> For the complete documentation index, see [llms.txt](https://cylexdev.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cylexdev.gitbook.io/docs/cylex-phone/exports-and-events/adding-custom-apps/javascript.md).

# Javascript

#### Iframe → Phone Communication (JavaScript)

Send messages from your custom app's iframe back to the phone.

```javascript
// Send a notification from the custom app
parent.postMessage({
    type: "cylex_phone",
    appId: "my_custom_app",
    action: "notification",
    data: {
        title: "New Alert",
        description: "Something happened!",
        icon: "https://example.com/icon.svg"
    }
}, "*");

// Close the custom app and return to home screen
parent.postMessage({
    type: "cylex_phone",
    appId: "my_custom_app",
    action: "close"
}, "*");

// Send data back to the Lua resource (triggers NUI callback + events)
parent.postMessage({
    type: "cylex_phone",
    appId: "my_custom_app",
    action: "nuiCallback",
    data: {
        action: "purchaseItem",
        data: { itemId: 42, quantity: 1 }
    }
}, "*");
```
