How can I display raw HTML, generated by an applet, without saving it on the server?

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++) {
          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
  function appletHtml(arg) {
    DDD.innerHTML = arg;
<PARAM NAME=text VALUE="You know, it can be done!">
<Div ID=DDD>
hi there!

== data.html
Look, it changes...
</DIV> </BODY> </HTML>
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.