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.

//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);
        }}
    );
});