Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IFRAME - getElementByID error!! 1

Status
Not open for further replies.

rajkum

Programmer
Jul 30, 2003
48
US
Please Help!!
Everytime I access the page below .. i get the following error :

"'document.getElementById(...).contentWindow.document.body' is null or not an object"

The page is as below: Its simple .. I am just trying to put some stuff in an editable iframe.




<HTML>
<HEAD>
<TITLE>Title</TITLE>
</HEAD>

<%
someInput = "<p>asa asa sa sas <b>asa</b> sa <i>sas a sa</i>sa a a sas a</p>"
%>

<BODY>
<FORM name = "formName"
method = "POST"
action = "">

<iframe src = "some.asp"
id = "frmName"
WIDTH = "100%"
HEIGHT = "200PX"
onload = "doIt()">
</iframe>



<script language="JavaScript">

function doIt()
{
frames.frmName.document.designMode = 'On';
document.getElementById('frmName').contentWindow.document.body.innerHTML = "<%= someInput %>";

}
</script>


</FORM>
</BODY>
</HTML>
 
works for me in Moz, provided you also give the iframe a name attribute = "frmName"

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
show us the whole GENERATED code for your page after it is rendered - NOT the asp code.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
This IFRAME/design stuff is kinda tricky... two problems here:
- each time you change something (designMode, innerHTML), onload fires again.
- shortly after designMode goes on, document is not available. Browser exposes it as null, and error appears.

Try this:

Code:
<script language="JavaScript">
var fired = false;

function doIt()
{	if (!fired)
	{	fired = true;
		document.frames["frmName"].document.designMode = "On";
		setTimeout ("doIt2()", 10 );
	}
}

function doIt2()
{	document.frames["frmName"].document.body.innerHTML = "<% = someInput %>";
}
</script>

I'm not sure what some.asp does but if it fills up initial content, place <% = someInput %> there.
Now things become a bit simpler because events won't do fireworks:

Code:
function doIt()
{	document.frames["frmName"].document.designMode = "On";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top