Saturday, November 21, 2009

CRM 4.0 Read Only Iframe - A better solution

I already posted about creating a read only iframe in the past but the solution offered here is by far better and integrates nicely with CRM.
The idea, in a nut shell, is to create an upper blocking layer inside the iframe. The layer is decorated with an alpha filter which makes it look disabled and also presents a watermark text to the user. The helper object also accepts an alert text that is shown to the user when he tries to click inside the frame.
Feel free to change the opacity, colors and fonts for best appearance. This code, as usual, should be pasted into the onload event handler and published.

function IframeReadOnlyHelper(sIframeId)
var iro = this;
iro.Iframe = document.getElementById(sIframeId);
if (!iro.Iframe)
alert("IFRAME with id " + sIframeId + " is missing");

iro.WatermarkText = "";
iro.AlertMessage = "";

iro.OnIframeReady = function()
if (iro.Iframe.readyState != 'complete')

var iframeDoc = iro.Iframe.contentWindow.document;
var iframeBody = iframeDoc.body;
var roSpan = iframeDoc.createElement("SPAN");

var roStyle = "overflow:hidden;";
roStyle += "position:absolute;";
roStyle += "z-index:1;";
roStyle += "left:0px;";
roStyle += "top:0px;";
roStyle += "height:100%;";
roStyle += "text-align:center;";
roStyle += "background-color:gray;";
roStyle += "font:72px Tahoma;";
roStyle += "filter:alpha(opacity=20)"; = roStyle;


if (iro.WatermarkText != "")
roSpan.innerHTML = "<div style='height:100;'><br>" + iro.WatermarkText + "</div>";

if (iro.AlertMessage != "")
roSpan.attachEvent("onclick", function(){alert(iro.AlertMessage);});

iro.Disable = function()
iro.Iframe.onreadystatechange = iro.OnIframeReady;

function OnCrmPageLoad()
//Load IFRAME with any URL
var iframeActivity = document.all.IFRAME_account_association;
iframeActivity.src = "areas.aspx?oId=%7b50387202-6F73-DE11-9F19-0003FF230264%7d&oType=1&security=852023&tabSet=areaActivities";

//Use IframeReadOnlyHelper
var roIframe = new IframeReadOnlyHelper("IFRAME ID");
roIframe.WatermarkText = "Read Only";
roIframe.AlertMessage = "This Grid is Disabled";



Stanza said...

Hi Adi,

Sorry this message had no relation to the post but I cannot find another way of getting in touch with you.

I noticed that you posted a solution on the Dynamics CRM forum about checking if any notes have been created on a record upon save. I have replied to this thread but have not got a response yet. Here is the thread:

Basically I want to be able to get the GUID of a selected note record when the form is saved. I have been posting this on the forum but have not have much luck with responses. I believe this pretty doable looking at your javascript code .

I would really appreciate if you could help me out here as I am desperate for some answers.

Many thanks,


Adi Katz said...

Hi Stanley, I posted back on that thread. You should write a plug-in to get the notes from the current entity update message (client save).

Stanza said...

Hi Adi,

I've just replied to that thread.
I really want to get the GUID of a selected note record when I click on a custom button on the form.
I used the onsave method as just one example.



Van Tay said...

Hi Adi,

Just wondering if you knew how to color code a field inside an IFrame ?


Matthew Mead said...

Very nice Adi, looks and works great!

Blogger said...

If you are looking into earning cash from your traffic via popunder advertisments - you can embed one of the biggest companies - Clickadu.