JApplet根据javascript中HTML的窗口宽度和高度设置宽度和高度

时间:2012-03-13 18:06:27

标签: javascript html japplet

我是新手,这可能是一个简单的修复。我目前正在使用javascript获取窗口高度和宽度,并希望使用javascript变量设置applet的高度和宽度。

这是我的代码:

<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>

我希望代码:width="1300" height="700"为:width = winW height = winH。我希望变量值在<applet>标签中给出宽度和高度。

有人能告诉我怎么做吗?

如果我需要澄清,请告诉我。

1 个答案:

答案 0 :(得分:0)

一种方法是在document.writeln()内写这样的applet ......

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