Answered by:
Iframe Read Only

Question
-
Hi frnds,
I have added one iframe in my custom entity. My requirement was to make the iframe disabled or read only. So anyone can give any idea or sample code to make the iframe disabled or readonly.
Thanks & Regards
Priya.Tuesday, August 12, 2008 3:59 PM
Answers
-
var IFRAME_test = null;
function OnCrmPageLoad()
{
//Set Object Variable
IFRAME_test = document.all.IFRAME_test;
//Attach to the change event
IFRAME_test.attachEvent( "onreadystatechange" , OnIframeTestReady );
IFRAME_test.src = getFrameSource('new_abcs_new_tests');
}function OnIframeTestReady()
{
//Override the onmousedown event
IFRAME_test.contentWindow.document.onmousedown = function(){
alert("This iframe is ReadOnly");
return false;
};
}getFrameSource = function( tabSet )
{
if (crmForm.ObjectId !=null)
{
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId="+ oId + "&oType=" + oType + "&security=" + security+ "&tabSet=" + tabSet;
}
else
{
return "about:blank";
}
}
OnCrmPageLoad();- Marked as answer by DavidJennawayMVP, Moderator Thursday, April 30, 2009 8:31 AM
Thursday, August 14, 2008 2:46 PM -
The whole idea is using an alert to steal the IFRAME focus. You can do the same thing by using a window.open and closing it immediately.
Replace the alert with:
var stubWin = window.open(‘about:blank’,’’,’toolbars=0,width=100,height=100,top=10000,left=10000’);
stubWin.close();
This places the window beyond the user's desktop.
Adi
- Marked as answer by DavidJennawayMVP, Moderator Thursday, April 30, 2009 8:31 AM
Monday, August 18, 2008 6:41 PM
All replies
-
Add the following code to the onload event.
document.all.<IFRAME ID>.contentWindow.document.onmousedown = function(){alert('[IFRAME DISABLED MSG]');return false;};
Adi
Tuesday, August 12, 2008 7:18 PM -
Hi Adi thanks for ur reply, I added the code to the onload event. But its not working for me even no alert msg.
Below is my onload code:
document.all.IFRAME_test.contentWindow.document.onmousedown = function(){alert("Ifram disabled");return false;};
Check whether this code correct or not. My requirement was to make the entire iframe readonly.
Thanks in advance.
Thanks & Regards
Priya.Wednesday, August 13, 2008 5:09 AM -
You need to wait until the iframe is completely loaded.
var IFRAME_test = null;
function OnCrmPageLoad()
{
//Set Object Variable
IFRAME_test = document.all.IFRAME_test;//Attach to the change event
IFRAME_test.attachEvent( "onreadystatechange" , OnIframeTestReady );
}function OnIframeTestReady()
{
//Override the onmousedown event
IFRAME_test.contentWindow.document.onmousedown = function(){alert("This iframe is ReadOnly");
return false;
};
}OnCrmPageLoad();
Wednesday, August 13, 2008 7:12 AM -
Hi Adi, I added ur code in my iframe still my iframe is not disabled. Below is my onload code pls review my code and correct my mistake adi. Thanks in advance.
var IFRAME_test = null;
function OnCrmPageLoad()
{
//Set Object Variable
IFRAME_test = document.all.IFRAME_test;//Attach to the change event
IFRAME_test.attachEvent( "onreadystatechange" , OnIframeTestReady );
}function OnIframeTestReady()
{
//Override the onmousedown event
IFRAME_test.contentWindow.document.onmousedown = function(){crmForm.all.IFRAME_test.src = getFrameSource('new_abcs_new_tests');
alert("This iframe is ReadOnly");
return false;
};
}OnCrmPageLoad();
getFrameSource = function( tabSet )
{
if (crmForm.ObjectId !=null)
{
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId="+ oId + "&oType=" + oType + "&security=" + security
+ "&tabSet=" + tabSet;
}
else
{
return "about:blank";
}
}
if(crmForm.FormType == 1)
{
crmForm.all.IFRAME_test.src = "about:blank";
}
Thanks & Advance
Priya.Wednesday, August 13, 2008 3:47 PM -
var IFRAME_test = null;
function OnCrmPageLoad()
{
//Set Object Variable
IFRAME_test = document.all.IFRAME_test;
//Attach to the change event
IFRAME_test.attachEvent( "onreadystatechange" , OnIframeTestReady );
IFRAME_test.src = getFrameSource('new_abcs_new_tests');
}function OnIframeTestReady()
{
//Override the onmousedown event
IFRAME_test.contentWindow.document.onmousedown = function(){
alert("This iframe is ReadOnly");
return false;
};
}getFrameSource = function( tabSet )
{
if (crmForm.ObjectId !=null)
{
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId="+ oId + "&oType=" + oType + "&security=" + security+ "&tabSet=" + tabSet;
}
else
{
return "about:blank";
}
}
OnCrmPageLoad();- Marked as answer by DavidJennawayMVP, Moderator Thursday, April 30, 2009 8:31 AM
Thursday, August 14, 2008 2:46 PM -
Hi Adi, Thank you very much for ur reply. Yours code works superb adi now i make my iframe readonly. If i remove the alert its not working adi i dnt know y. Thanks you so much for helping me adi.
Thanks & Regards
Priya.Monday, August 18, 2008 4:51 PM -
The whole idea is using an alert to steal the IFRAME focus. You can do the same thing by using a window.open and closing it immediately.
Replace the alert with:
var stubWin = window.open(‘about:blank’,’’,’toolbars=0,width=100,height=100,top=10000,left=10000’);
stubWin.close();
This places the window beyond the user's desktop.
Adi
- Marked as answer by DavidJennawayMVP, Moderator Thursday, April 30, 2009 8:31 AM
Monday, August 18, 2008 6:41 PM -
Please, show a sample iframe and html code to implement iframe readonly code.
thanks in advance
Rops
- Proposed as answer by DUUDE1453151313 Thursday, May 5, 2011 10:16 PM
Saturday, June 5, 2010 5:40 PM -
I'm aware that it's been a year since the last entry but I've been googling since 6 hours in order to find how to make an iframe readonly. Finally I found it, actually it's a quite simpe coding :
<script>
window.onload = function () {
var iframes = document.getElementsByTagName('iframe');
for (var i = 0, l = iframes.length; i < l; i++) {
var iframe = iframes[i],
d = document.createElement('div');
d.style.width = iframe.offsetWidth + 'px';
d.style.height = iframe.offsetHeight + 'px';
d.style.top = iframe.offsetTop + 'px';
d.style.left = iframe.offsetLeft + 'px';
d.style.position = 'absolute';
d.style.opacity = '0';
d.style.filter = 'alpha(opacity=0)';
d.style.background = 'black';
iframe.offsetParent.appendChild(d);
}
};
</script>
<iframe....
Hoping that will be useful for others in the futur
Regards
Thursday, May 5, 2011 10:19 PM -
I tried your code but it is not working for me. My Requirement is i want an iframe to be disabled or make it readonly so that the users cann't modify it.
my iframe:
<iframe id="IndexFieldsPanelFrame" unselectable="yes" frameborder="1" src="" width=100% height=100%>IndexFieldsPanelFrame</iframe>
Any suggestions on this.
Thanks,
Venkat
Thursday, November 3, 2011 3:54 AM