Newer Version Available

This content describes an older version of this product. View Latest

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.

1//Subscribe to the parent window onscroll event.
2Sfdc.canvas(function() {
3    sr = JSON.parse('<%=signedRequestJson%>');
4    // Capture the onScrolling event of the parent window
5    Sfdc.canvas.client.subscribe(sr.client,
6        {name : 'canvas.scroll', onData : function (event) {
7            console.log("Parent's contentHeight; " + event.heights.contentHeight);
8            console.log("Parent's pageHeight; " + event.heights.pageHeight);
9            console.log("Parent's scrollTop; " + event.heights.scrollTop);
10            console.log("Parent's contentWidth; " + event.widths.contentWidth);
11            console.log("Parent's pageWidth; " + event.widths.pageWidth);
12            console.log("Parent's scrollLeft; " + event.widths.scrollLeft);
13        }}
14    );
15});