OnReadyStateComplete does not start

I am trying to add a Javascript CRM web resource and I am trying to manipulate iframes, but the OnReadyStateComplete iframe event is not firing. Below, the first warning works, but the second doesn't.

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');
     }
    }

      

+3


source to share


2 answers


I had a similar problem, but only with iframe content from other domians. I think these are security constraints preventing events from being raised. We worked on it using an aspx page on the server that loaded the content and recreated it for the xrm script.



+1


source


The IFrame control has no property or event OnReadyStateComplete

. The SDK documentation only points to the menu item available in the form designer.

However, it is actually possible to attach a function to the onload

IFrame event in a supported way:



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

      

The function getObject

returns an IFrame object that gives you access to the iFrame and the document contained in its properties contentWindow

and contentDocument

. (See also HTML DOM IFrame Object .)

0


source







All Articles