3

I try to add CRM javascript web resource and try to manage iframe elements, but iframe OnReadyStateComplete event is not fired. Below, the first alert works but the second does not.

function hello()
    {
        var audioPath= Xrm.Page.data.entity.attributes.get("new_audiopath").getValue();
         //var myAudio = document.createElement('audio');
         //myAudio.setAttribute('src', audioPath);
         // myAudio.play(); 

            var IFrame = Xrm.Page.ui.controls.get("IFRAME_Play");
            alert(audioPath);
            //var myAudio =Xrm.Page.ui.controls.get("audioSource");

          IFrame.OnReadyStateComplete=function(){
          alert('iframe ready');
     }
    }
Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
irohamca
  • 497
  • 3
  • 19

2 Answers2

1

I had similar problem, but only with iframe content from other domians. I think it's the security restrictions, not allowing to raise events. We worked around it with a aspx-page on the server, which downloaded the content, and recreated it for the xrm script.

Jesper Jensen
  • 835
  • 8
  • 16
  • http://sadi:8090/play.aspx ---> iframe url http://sadi:5555/ ---> dynamics crm url They are in the same domain. – irohamca Jun 05 '15 at 10:52
  • The issue here is that the event is not fired. I doubt this has anything to do with XSS, because in the sample above there is no scripting code trying to access the document in the containing window. – Henk van Boeijen Apr 04 '16 at 15:36
1

The IFrame control does not have an OnReadyStateComplete property or event. The SDK documentation only hints at the menu-option that is available in the form designer.

However, it is actually possible to attach a function to the onload event of the IFrame in a supported way:

var iFrameElement = Xrm.Page.getControl("IFRAME_Play").getObject();
iFrameElement.addEventListener("load", function() {
    alert("IFrame Play loaded!");
}

Function getObject returns an IFrame object giving you access to the iFrame's window and the document it contains through its contentWindow and contentDocument properties. (See also HTML DOM IFrame Object.)

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42