getContentWindow (Client API reference)

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


This method is supported only on Unified Interface.

Control types supported

iframe, web resource


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


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.


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) {
            function (contentWindow) {
                contentWindow.setClientApiContext(Xrm, formContext);

Similar initialization code should be added to a TabStateChange event handler if such initialization is necessary. Any initialization code should be idempotent if it is re-used. For performance reasons, the form may destroy and re-initialize the control during tab navigations.