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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I load content into an IFRAME without using a src param

Status
Not open for further replies.

TheDrider

Programmer
Jun 27, 2001
110
US
I would like to load an IFRame with known html content from a query in the main page.

Something like this. I want to set the IFrame content without needing a separate src URL. I already have the content I need to display in the frame.

Code:
<td>
<IFRAME ID="NarrFrame" HEIGHT="100" WIDTH="700"
                FRAMEBORDER="1" SCROLLING="YES">
</IFRAME>
</td>

<script type="text/javascript">
<!--
myHTML = 'some HTML code';

frame = document.getElementById("NarrFrame");
frame.document.open();
frame.document.write(myHTML);
frame.document.close();
//-->
</script>
 
As far as I can tell that will work. Have you tried it? Are you getting an error?


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
No, I don't get an error, but the HTML is written to the parent document instead of inside the IFRAME.
 
Try changing the name of your variable to daFrame or myFrame. frame is a reserved word and is probably doing very strange things to your program.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Tried that too but still fails. This the entire sample htm page. It put the IFRAME in the table, but writes the HTML below and outside of it, directly in the parent document.

Code:
<table border=1 bgcolor="ff00ff">
<tr><td>Cell 1-1</td></tr>
<tr><td>
<IFRAME ID="NarrFrame" HEIGHT="75" WIDTH="700"
        FRAMEBORDER="1" SCROLLING="YES"></IFRAME>
</td></tr></table>

<script type="text/javascript">
<!--
	myHTML = '<span style="color:008000">SOME GREEN TEXT</span>';
	myFrame = document.getElementById("NarrFrame");
	myFrame.document.open();
	myFrame.document.write(myHTML);
	myFrame.document.close();
//-->
</script>
 
Functional example:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>

<script language="javascript"><!--

function fillFrame() {
   var f = top.frames['i'];
   with (f.document) {
      open();
      writeln('some html goes here');
      close();
   }
}

//--></script>

</head>

<body>

<a href="#" onclick="fillFrame(); return false;">Fill Frame</a>
<iframe id="i" name="i" src=""></iframe>


</body>
</html>

*cLFlaVA
----------------------------
[tt]clean slate...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
It turned out to be the way I was referencing the iframe object.


Code:
//this works
myFrame = top.frames['NarrFrame'];

//this does not
myFrame = document.getElementById("NarrFrame");

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top