Creating a Dynamic IFRAME

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Change the Page Displayed in the IFRAME

You may want to change the target of the IFRAME based on considerations such as the data in the form or whether the user is working offline. You can set the target of the IFRAME dynamically.

Note   When you change the URL for the IFRAME, parameters are not passed to the new URL automatically. You need to append the querystring parameters to the URL before setting the src property.


The following code example shows you how to set the src for the IFRAME and pass the parameters.

var params = crmForm.all.IFRAME_test.url;
params = params.substr(params.indexOf('?'));
var newTarget = "http://mysite/mypage.aspx";
newTarget = newTarget + params;
crmForm.all.IFRAME_test.src = newTarget ;

Allow Access to Form Data

If you trust the target site of the IFRAME you can disable the security attribute so cross-frame scripting is enabled. This allows the target page to reference or change data in the entity form.

A script in the target of the IFRAME can access objects in the parent. The crmForm cannot be referenced by name because it does not have an ID associated with it, but it is the first form in the forms collection.

For example, to set the value of a variable named AccountName to the name of the Account, use the following code in a page that is the target of an IFRAME in the account form:

var AccountName = parent.document.forms[0];

This value, or any other value in the form, can then be processed by the Web page that is the target of the IFRAME.

The Web page that is the target of the IFRAME can also update the crmForm field values, as shown in the following code example:

parent.document.forms[0] = AccountName;

Access the IFRAME Page With Form Scripts

You can access the content of a page displayed in an IFRAME with form scripts by using the IFRAME contentWindow property. For example:

var nameFieldValue = crmForm.all.new_name.DataValue;
var destinationNode = crmForm.all.IFRAME_test.contentWindow.document.getElementById('test');
destinationNode.innerText += nameFieldValue;

See Also


Other Resources

© 2010 Microsoft Corporation. All rights reserved.