Sending html data to the IFrame contents

J

John Chen

I need to use iframe to create a floating frame. But the contents in the
iframe is not a external html file. Rather, it will be dynamically created
by jsp. How can I set the src attribute to a URL of a dynamically created
html contents rather than a static html file. Thanks.
 
D

Douglas Crockford

I need to use iframe to create a floating frame. But the contents in the
iframe is not a external html file. Rather, it will be dynamically created
by jsp. How can I set the src attribute to a URL of a dynamically created
html contents rather than a static html file. Thanks.

Your notion of dynamic and static in this case is strictly on the server's side.
All the browser knows is that it gets a wad of html via http. All such wads are
provided in response to the browser sending a url in an http request. The shape
of that url depends on the application running in the appserver.
 
D

DU

John said:
I need to use iframe to create a floating frame.

I do not understand what you mean with "floating" frame.
An url of your current webpage would have been useful here.

But the contents in the
iframe is not a external html file. Rather, it will be dynamically created
by jsp. How can I set the src attribute to a URL of a dynamically created
html contents rather than a static html file.

Not sure I understand correctly your question.
You can use DOM 2 methods to create a chunk of html code (or even
document fragment) and then insert it (almost anywhere, at any place)
into the iframed document. Or append it. Or replace current html content
of the iframe. Whatever you do, the src attribute value of the iframe
should not change.

E.g.: appending a div in a iframe from its own parent file

<script type="text/javascript">
function appendDivInIframedDocument()
{
var DOMdiv = frames["IframeName"].document.createElement("div");
DOMdiv.style.color = "green";
var DOMspan = frames["IframeName"].document.createElement("span");
DOMspan.style.color = "red";
var DOMspantext = frames["IframeName"].document.createTextNode("This is
the text node value of the span and it is red");
DOMspan.appendChild(DOMspantext);
DOMdiv.appendChild(DOMspan);
var DOMdivtext = frames["IframeName"].document.createTextNode(" while
this green text is part of the div text node. The green and red text
were dynamically inserted in the iframed document.");
DOMdiv.appendChild(DOMdivtext);
frames["IframeName"].document.body.insertBefore(DOMdiv,
frames["IframeName"].document.body.childNodes[1]);
document.getElementById("ButtonCreateAndInsert").disabled = true;
}
</script>
</head>

<body>

<iframe src="OriginalDocumentIframe.html" name="IframeName" width="500"
height="200" style="border:3px solid blue;">[Your user agent does not
support iframes or is currently configured not to display iframes. If
you're using Opera 6+, you can enable iframe with
File/Preferences...Alt+P/Page style/Enable inline frames.]</iframe>

<p><button type="button" id="ButtonCreateAndInsert"
onclick="appendDivInIframedDocument();">Create and insert a div into the
Iframe document</button></p>

(...)

Works in MSIE 6 for Windows, Opera 7, Mozilla-based browsers, NS 7.1,
etc.. and in other DOM 2 compliant browsers as long as the markup code
syntax is valid.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 
C

Chris Riesbeck

John Chen said:
I need to use iframe to create a floating frame. But the contents in the
iframe is not a external html file. Rather, it will be dynamically created
by jsp. How can I set the src attribute to a URL of a dynamically created
html contents rather than a static html file. Thanks.

There's no difference. Just write the URL for the JSP as
you would an HTML file. The browser just sends the URL
to the server and displays in the frame whatever
the server returns.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,091
Messages
2,570,604
Members
47,223
Latest member
smithjens316

Latest Threads

Top