Aracılığıyla paylaş


Use an IFRAME and web resource controls on a form

 

Applies To: Dynamics CRM 2015

IFRAME and web resource controls embed content from another location in pages by using an HTML IFRAME element.

Note

IFRAME and web resource elements aren’t displayed in Microsoft Dynamics CRM for tablets. With Microsoft Dynamics CRM Online 2015 Update you can start early development and testing of touch-enabled controls for CRM for tablets by enabling the preview feature to display IFrames and web resources in CRM for tablets. More information: Create web resources and IFRAME content for use with the CRM for tablets client.

Note

The designs you choose for the form are also used for the Microsoft Dynamics CRM for Outlook reading pane and forms used by Microsoft Dynamics CRM for tablets. Web resources and IFRAMEs aren’t displayed using the Dynamics CRM for Outlook reading pane or CRM for tablets. If your IFRAME depends on access to the Xrm.Page object of the page or any form event handlers, you should configure the IFRAME so that it's not visible by default.

You can use an IFRAME to display the contents from another website in a form, for example, in an ASP.NET page. Displaying an entity form within an IFrame embedded in another entity form is not supported.

You can use one of the following web resources to display the contents of web resources in a form:

The following sections describe your options if you want these controls to show more than static content.

In This Topic

Select whether to restrict cross-frame scripting

Pass contextual information about the record

Pass form data

Change the URL

Select whether to restrict cross-frame scripting

Use the Restrict cross-frame scripting, where supported option when you do not fully trust the content displayed in an IFRAME. When this option is selected, the IFRAME has the attributes set that are listed in the following table.

Attribute

Description

security=”restricted”

This attribute is supported only by versions of Internet Explorer no earlier than version 6. The security attribute applies the user security setting Restricted Sites to the source file of the IFRAME. (Zone settings are found on the Security tab of the Internet Options dialog box.) By default, scripting isn’t enabled in the Restricted Sites zone. By changing the security settings of the zone, various negative results can occur, including allowing scripts to run. For more information, see security attribute.

sandbox=””

For browsers that support this attribute, the content in the IFRAME is essentially limited to only displaying information. The following restrictions could be applied:

  • Browser plug-ins are disabled.

  • Forms and scripts are disabled.

  • Links to other browsing contexts are disabled.

  • Content is treated as from a different domain even if the domain is the same.

This attribute is defined by W3C and is supported by the following browsers:

  • Internet Explorer 10

  • Google Chrome

  • Apple Safari

  • Mozilla Firefox

For more information about the sandbox attribute see:

Enabling IFrame communication across domains

There are times when you want to enable communication for an IFRAME that contains content on a different domain. Window.postMessage is a browser method that provides this capability for versions of Internet Explorer no earlier than Internet Explorer 8. Google Chrome, Mozilla Firefox, and Apple Safari also support it. For more information about using postMessage, see the following blog posts:

Pass contextual information about the record

You can provide contextual information by passing parameters to the URL defined in the control. The page that is displayed in the frame must be able to process parameters passed to it. All the parameters in the following table are passed if the IFRAME or web resource is configured by using the Pass record object-type code and unique identifier as parameters option. The corresponding form XML element is <PassParameters> (FormXml).

You can specify whether all the parameters in the following table will be passed.

Parameter

Name

Description

typename

Entity Name

The name of the entity.

type

Entity Type Code

The integer that uniquely identifies the entity in a specific organization.

id

Object GUID

A GUID that represents a record.

orgname

Organization Name

The unique name of the organization.

userlcid

User Language Code

The language code identifier that is being used by the current user.

orglcid

Organization Language Code

The language code identifier that represents the base language for the organization.

 Language codes are four-digit or five-digit locale IDs. Valid locale ID values can be found at Locale ID (LCID) Chart).

Note

We suggest that you use the entity name instead of the type code because the entity type code for custom entities may be different between Microsoft Dynamics CRM organizations.

Example

The following sample shows the URL without parameters.

http://myserver/mypage.aspx

The following sample shows the URL with parameters.

http://myserver/mypage.aspx?id=%7bB2232821-A775-DF11-8DD1-00155DBA3809%7d&orglcid=1033&orgname=adventureworkscycle&type=1&typename=account&userlcid=1033

Read passed parameters

Passed parameters are typically read in the target .aspx page by using the HttpRequest.QueryString property. In an HTML page, the parameters can be accessed by using the window.location.search property in JavaScript. For more information, see HttpRequest.QueryString Property and search Property.

Pass form data

Use the 6881e99b-45e4-4552-8355-2eef296f2cd8#BKMK_getValue method on the attributes that contain the data that you want to pass to the other website, and compose a string of the query string arguments the other page will be able to use. Then use a d88d5f21-6385-443b-91f2-0ec0c16b1324#BKMK_FieldOnChangeEvent, d88d5f21-6385-443b-91f2-0ec0c16b1324#BKMK_IFRAMEOnReadyStateCompleteEvent, or d88d5f21-6385-443b-91f2-0ec0c16b1324#BKMK_TabTabStateChangeEvent and the 51828fe3-f6ff-4f97-80ed-b06b3a354955#BKMK_setSrc method to append your parameters to the src property of the IFRAME or web resource.

If you’re using the data parameter to pass data to a Silverlight web resource, you can use the 51828fe3-f6ff-4f97-80ed-b06b3a354955#BKMK_getData and 51828fe3-f6ff-4f97-80ed-b06b3a354955#BKMK_setData methods to manipulate the value passed via the data parameter. For webpage (HTML) web resources, use the 51828fe3-f6ff-4f97-80ed-b06b3a354955#BKMK_setSrc method to manipulate the querystring parameter directly.

Avoid using the d88d5f21-6385-443b-91f2-0ec0c16b1324#BKMK_OnLoadEvent. IFRAMES and web resources load asynchronously and the frame may not have finished loading before the Onload event script finishes. This can cause the src property of the IFRAME or web resource you have changed to be overwritten by the default value of the IFRAME or web resource URL property.

Change the URL

You may want to change the target of the IFRAME based on such considerations 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 target page for the IFRAME, parameters aren’t passed to the new URL automatically. You must append the query string parameters to the URL before you use the setSrc method.

Example

The following sample shows you how to set the src property for the IFRAME and any parameters by using the onChange event of an option set field.

//Get the value of an option set attribute
var value = Xrm.Page.data.entity.attributes.get("new_pagechooser").getValue();
var newTarget = "";
//Set the target based on the value of the option set
switch (value) {
    case 100000001:
        newTarget = "http://myServer/test/pageOne.aspx";
        break;
    default:
        newTarget = "http://myServer/test/pageTwo.aspx";
        break;
}
//Get the default URL for the IFRAME, which includes the 
// query string parameters
var IFrame = Xrm.Page.ui.controls.get("IFRAME_test");
var Url = IFrame.getSrc();
// Capture the parameters
var params = Url.substr(Url.indexOf("?"));
//Append the parameters to the new page URL
newTarget = newTarget + params;
// Use the setSrc method so that the IFRAME uses the
// new page with the existing parameters
IFrame.setSrc(newTarget);

See Also

Write code for Microsoft Dynamics CRM forms
Use JavaScript with Microsoft Dynamics CRM
Form scripting quick reference

© 2016 Microsoft. All rights reserved. Copyright