Monday, May 18, 2009

How to Create a Dynamic IFRAME

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.
Example
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].all.name.DataValue;


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].all.name.DataValue = AccountName;


Note : Scripts in Microsoft Dynamics CRM cannot interact with DHTML elements within the IFRAME. This is a security restriction that is set within Internet Explorer for all IFRAME elements.

No comments: