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