0
votes

I'm facing a problem with an IFrame on MS CRM 2011. I'm trying to generate HTML code and write it into an IFrame. I'm quite new to CRM development so I hope you could guide me to a solution.

After I generate the HTML content (IframeHTML) via JavaScript I try to write that content to an IFrame and then reload the whole Form. Everything is working fine until I reach my last command

var control = document.getElementById("IFRAME_name");
control.contentWindow.document.open();
control.contentWindow.document.write(IframeHTML);
control.contentWindow.document.close();
control.location.reload(true);

The script is executed on OnLoad of the Form, but it gives me an alert that

Access is denied

at the end.

If I replace the first line with :

var control = Xrm.Page.ui.controls.get("IFRAME_name");

it tells me

Document is not supported.

I'm not sure if I recognized what the problem here is so any help would be nice.

1
Yeah, you can't use Xrm.Page to get the IFRAME, so the first block of code you have looks good. I use very similar code in CRM 2011 (see below) and it works fine, so I'm assuming your error is due to something else. var iFrame = document.getElementById("IFRAME_name"); var doc = iFrame.contentDocument; if (doc == undefined || doc == null) { doc = iFrame.contentWindow.document; } doc.open(); doc.write(IframeHTML); doc.close(); - Peter Majeed
Actually, a difference may be in the control.location.reload(true) line. Do you need that line of code for any reason? - Peter Majeed
Did you ever figure this out? - Polshgiant

1 Answers

0
votes

You have to activate Crossframe Scripting in the IFRAME properties.

Have you done that?

Regarding the Xrm.Page call, you can get the IFRAME using

var control = Xrm.Page.ui.controls.get("IFRAME_name").getObject();

This is the supported way to get the IFRAME, so you should use that.