Embedding Java Applet into .html file

Making applets work across a wide range of browsers is surprisingly hard. The tags weren’t properly standardized in the early days, so Internet Explorer and Mozilla went separate directions.

Sun developed a generic JavaScript to handle all the specific browser quirks, so that you don’t have to worry about browser compatibility.

Add this to your <head> section:

<script src="https://www.java.com/js/deployJava.js"></script>

And this to <body> section:

<script>
    var attributes = {codebase: 'http://my.url/my/path/to/codebase',
                      code: 'my.main.Applet.class',
                      archive: 'my-archive.jar',
                      width: '800', 
                      height: '600'};
    var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
    var version = '1.5'; // JDK version
    deployJava.runApplet(attributes, parameters, version);
</script>

See Java™ Rich Internet Applications Deployment Advice for a detailed explanation of the script and all the possible options.

Leave a Comment