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 an 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("WebResource_CustomName");
if (wrControl) {
wrControl.getContentWindow().then(
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's reused. For performance reasons, the form may destroy and reinitialize the control during tab navigation.
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho