---
schema_version: "1"
id: 859aa83c112160c4790d50d9dc140d61874bf716c67ad49dca2c4903e54ce8ef
title: Subscribing to Parent Events
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/canvas-app-subscribe-code-example.md
canonical_url: https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-subscribe-code-example.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e92bc2040a13989b95ef60e13701b03aedb12cfaa9f29a278b58d69581fc0144
products:
  - Canvas Developer Guide
  - Platform Developer Content
---

# Subscribing to Parent Events

The following code example shows how to call the `subscribe` method so that a canvas app can subscribe to parent events. This example handles the `onscroll` event that fires when the user scrolls in the parent window.

<!-- otherprops: set_clipboard -->
```java
//Subscribe to the parent window onscroll event.
Sfdc.canvas(function() {
    sr = JSON.parse('<%=signedRequestJson%>');
    // Capture the onScrolling event of the parent window
    Sfdc.canvas.client.subscribe(sr.client,
        {name : 'canvas.scroll', onData : function (event) {
            console.log("Parent's contentHeight; " + event.heights.contentHeight);
            console.log("Parent's pageHeight; " + event.heights.pageHeight);
            console.log("Parent's scrollTop; " + event.heights.scrollTop);
            console.log("Parent's contentWidth; " + event.widths.contentWidth);
            console.log("Parent's pageWidth; " + event.widths.pageWidth);
            console.log("Parent's scrollLeft; " + event.widths.scrollLeft);
        }}
    );
});
```

**See Also**  


-   [Resizing a Canvas App](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-resizing.md)

