How can I display raw HTML, generated by an applet, without saving it on the server?
Created Apr 11, 2000
Andre van Dalen You can display HTML dynamically generated by your applet by passing it first to a JavaScript method,
(see also this
FAQ)
that in turn puts the code into the page.
You can overwrite a document frame or change the innerHTML of a section with the HTML you get passed from the applet.
The following files give a working example for IE4, making it work on netscape is left as an exercise to the reader ;-)
== mkhtml.java
import java.applet.*;
import netscape.javascript.*;
public class mkhtml extends Applet {
public void start() {
try {
JSObject javaScript = JSObject.getWindow(this);
if (null != javaScript) {
String param = getParameter("text");
Object[] args = new Object[1];
for (int n = 1; n = param.length(); n++) {
Thread.sleep(200);
args[0] = "<html><body bgcolor=" + (0xffffff - 233 * n) +
"">Building text:<p><center>>b>" + param.substring(0, n) +
"</b></center><p>via an applet!</body></html>";
javaScript.call("appletHtml", args);
}
}
} catch (Exception ignore) {
}
}
}
== index.html
<HTML> <frameset cols="200,200">
<frame name=main src="main.html" >
<frame name=data src="data.html">
</frameset> </HTML>
== main.html
<HTML>
<SCRIPT>
function appletHtml(arg) {
parent.frames.data.document.write(arg);
parent.frames.data.document.close();
DDD.innerHTML = arg;
}
</SCRIPT>
<APPLET CODE="mkhtml.class" WIDTH=10 HEIGHT=10 MAYSCRIPT>
<PARAM NAME=text VALUE="You know, it can be done!">
</APPLET>
<Div ID=DDD>
hi there!
</Div>
</HTML>
== data.html
<HTML> <BODY> <DIV ID=THEFRAME>
Look, it changes...
</DIV> </BODY> </HTML>
==