1
votes

I have a web resource that I am calling inside of a dialog.

It seems that in a recent update of CRM Dynamics, they are now overwriting the window.frames object, which I used to get a list of all iframes before.

Here is a view of the frames object in the console..

enter image description here

Does anyone know how do I get access to the available iframes on the page?

Previous code that used to work...

 var found = false;
 $.each(parent.window.frames, function (i, val) {
        if (!found) {
            if (parent.window.frames[i].Xrm.Page.data != null) {
                console.log("got here, page data not null");
                found = true;
            }
        }
    });

Version of Dynamics: 7.0.2.53

1
Are you sure you really want to do this? Its unsupported. What is the end goal? - James Wood
The purpose is to get access to data on a form from the originating iframe. - TWilly

1 Answers

1
votes

You may try to get all IFrame controls using the following code:

var iframeControlArray = Xrm.Page.getControl(function (control, index) { 
    return control.getControlType() == "iframe"; 
});

and then access the IFrame DOM Object:

var iframeDomObject = iframeControlArray[0].getObject();
var iframeDocument = iframeDomObject.contentDocument  
        || iframeDomObject.contentWindow.document; 

And if the IFrame resource in the another domain and you have a full access to to it, it would be better to make "IFrame communication across domains" using window.postMessage(). More about it here: