By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Sending html data to the IFrame contents

P: n/a
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.

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> 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.

Jul 20 '05 #2

P: n/a
DU
John Chen wrote:
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").d isabled = 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/doctorunc...e7Section.html

Jul 20 '05 #3

P: n/a
In article <t9q9b.468155$uu5.81229@sccrnsc04>,
"John Chen" <jo*******@comcast.net> wrote:
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.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.