Suppose you have a CRM form that has several IFRAMES contained in multiple tabs. Loading such a form can sometimes create a performance issue on the client browser due to the frames all loading at the same time. One such way to reduce the hit on performance would be to delay loading an IFRAME until the tab it is on is clicked and made visible.
What we’re going to do is create a function that sets the source of the IFRAME and then we’ll attach the function to the onclick event of the tab. In this example, I have an IFRAME named ‘IFRAME_myiframe’ and I have set the original url to be ‘about:blank’. I want the IFRAME to display the Bing search engine when it’s tab is displayed.
IFRAME Load function
Setting an IFRAME source via javascript is a pretty simple piece of code that CRM customizers should be familiar with. We’re just going to wrap the code within a function:
LoadFrame = function() {
crmForm.all.IFRAME_myiframe.src='http://www.bing.com';
}
This function should be placed in the OnLoad of the form.
The Tab ElementNext, we need to identify the name of the specific tab we want. The id of any tab on a CRM form is ‘tabXTab’ where ‘X’ represents the zero-based index of the tab. So the first tab is named tab0Tab, the second is named tab1Tab, and so on. The tab I want to work with is the second tab, so the element I’m looking for is named ‘tab1Tab’.
Now that we’ve identified the tab element, let’s attach the load function:
document.getElementById('tab1Tab').onclick = LoadFrame;
Note: Place this code in the form’s OnLoad event, but make sure it comes AFTER the load function we defined above.
That’s all there is to it. Cheers!
Technorati Tags: CRM,Javascript,CRM IFRAME,CRM Customizations,CRM Scripting
Take a look and Get Ready
Update Rollup 9 for Microsoft Dynamics CRM 4.0 will be available February 11th
A list of current Update Rollups for Microsoft Dynamics CRM