---
schema_version: "1"
id: 57eabba0009a65056f1e7800373b3d824a8cc991ce31095cdf7160db181210b8
title: Publishing a Canvas Event from a Visualforce Page
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/canvas-framework/guides/platform-connect/using/resizing-in-vf/canvas-app-vf-publish-code-example.md
canonical_url: https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-vf-publish-code-example.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: fe5a234abfe3523a9a6b8808b075f6c93854cb2744e8c9408a900c0338204193
products:
  - Canvas Developer Guide
  - Platform Developer Content
---

# Publishing a Canvas Event from a Visualforce Page

The following code example shows how to call the `publish` method to publish the `myevent` event from a Visualforce page. Any canvas app that subscribes to this event will receive the event.

<!-- otherprops: set_clipboard -->
```java
    // Target all canvas apps.
    Sfdc.canvas.controller.publish({name : 'mynamespace.myevent',
                                    payload : {}});
```

The following code example shows how to call the `publish` method to publish an event to a specified canvas app from the Visualforce page.

If an event is published to specific canvas apps, even if other canvas apps on a Visualforce page are subscribed to it, only the canvas apps specified will receive that event. Using this code example, if the Visualforce page contained canvas apps app1, app2, and app3, and they all subscribed to `myevent`, only app1 would receive the event.

<!-- otherprops: set_clipboard -->
```java
    // Target a specific canvas app
    // where "app1" is the canvasId specified in the canvas component.
    // For example: <apex:canvasApp canvasId="app1">
    Sfdc.canvas.controller.publish({name : 'mynamespace.myevent',
                                    payload : {}, 
                                    target : {canvas : 'app1'}});
```

In the `target` parameter, you can specify multiple canvas apps by passing in an array of canvas apps: `target : [{canvas : 'app1'}, {canvas: 'app2'}]`.

**See Also**  


-   [Using Events between a Visualforce Page and a Canvas App](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-vf-app-resizing.md)
-   [Resizing a Canvas App in a Visualforce Page](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-vf-resize-code-example.md)
-   [Subscribing to Events](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-vf-subscribe-code-example.md)
-   [Unsubscribing from Events in a Visualforce Page](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-vf-unsubscribe-code-example.md)
-   [apex:canvasApp Component](https://developer.salesforce.com/docs/platform/canvas-framework/canvas-app-vf-component-ref.md)

