Search code examples
javascripthtmljapplet

JApplet setting width and height based on window width and height in HTML from javascript


I'm new and this might be a simple fix. I am currently getting the window height and width using javascript and want to set an applet's height and width using javascript variables.

Here is my code:

<html>
<title>Applet</title>
<head>

<script type="text/javascript">
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
 winW = document.body.offsetWidth;
 winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth ) {
 winW = document.documentElement.offsetWidth;
 winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
 winW = window.innerWidth;
 winH = window.innerHeight;
}
</script>


</head>
<body>
<script type="text/javascript">
document.writeln('Window width = '+winW);
document.writeln('Window height = '+winH);
</script>
<applet code="applet.class" 
        archive="applet7.jar, collections-generic-4.01.jar, colt-1.2.0.jar, jung-api-2.0.1, neo4j-kernel-1.6.M01.jar, blueprints-core-1.1.jar, jung-visualization-2.0.1.jar, jung-algorithms-2.0.1.jar, jung-3d-2.0.1.jar, jung-jai-samples-2.0.1.jar, jung-3d-demos-2.0.1.jar, jung-samples-2.0.1.jar, jung-io-2.0.1.jar, jung-graph-impl-2.0.1.jar, jung-jai-2.0.1.jar, blueprints-graph-sail-1.1.jar, blueprints-dex-graph-1.1.jar, blueprints-neo4j-graph-1.1.jar, blueprints-graph-jung-1.1.jar, blueprints-neo4jbatch-graph-1.1.jar, blueprints-sail-graph-1.1.jar, blueprints-orient-graph-1.1.jar, collections-generic-4.01.jar, blueprints-rexster-graph-1.1.jar, jta.jar, lucene-core-3.1.0.jar, neo4j-lucene-index-1.6.M01.jar, neo4j-remote-graphdb-0.8-1.2.M06.jar"
        width="1300" height="700">

</applet>

</body>
</html>

I want the code: width="1300" height="700" to be: width=winW height=winH. I want the variables values to be given to width and height in the <applet> tags.

Can some one tell me how to do this?

Please let me know if I need to clarify.


Solution

  • One way is to write the applet inside document.writeln() like this...

    document.writeln('<applet code="Dummy.class" width="'+winW+'" height="'+winH+'">');