Reputation: 507
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');
}
}
Upvotes: 3
Views: 1290
Reputation: 7918
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.)
Upvotes: 1
Reputation: 895
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.
Upvotes: 1