getContentWindow (Client API reference)

Returns the content window that represents an IFRAME or web resource.

Note

This method is supported only on Unified Interface.

Control types supported

iframe, web resource

Syntax

formContext.getControl(arg).getContentWindow().then(successCallback, errorCallback);

Parameters

Name Type Required Description
successCallback Function No A function to call when operation is executed successfully. A content window instance representing the IFRAME or web resource is passed to the function.
errorCallback Function No A function to call when the operation fails.

Return Value

On success, returns a promise that contains a content window instance representing an IFRAME or web resource.

Example

The following example shows how you can use this method with a HTML Web resource (new_myWebResource.htm).

First, add the following code in your HTML web resource:

// This script should be in the HTML web resource.
// No usage of Xrm or formContext should happen until this method is called.
function setClientApiContext(xrm, formContext) {
    // Optionally set Xrm and formContext as global variables on the page.
    window.Xrm = xrm;
    window._formContext = formContext;
     
    // Add script logic here that uses xrm or the formContext.
}

Next, add the following code in the form onLoad event handler:

// This should be in a script loaded on the form. 
// form_onload is a handler for the form onload event.
function form_onload(executionContext) {
    var formContext = executionContext.getFormContext();
    var wrControl = formContext.getControl("new_myWebResource.htm");
    if (wrControl) {
        wrControl.getContentWindow().then(
            function (contentWindow) {
                contentWindow.setClientApiContext(Xrm, formContext);
            }
        )
    }
}