下面的脚本能准确获取大部分浏览器的窗口大小。
代码如下:
ExampleApplet.htm:
<html>
<head>
<title>Applet Example</title>
</head>
<body style="height:100%;margin:0px;">
<object type="application/x-java-applet"
code="ExampleApplet.class" width="100" height="100" id="ExampleApplet">
<comment>
<applet code="ExampleApplet.class" width="100" height="100" name="ExampleApplet"></applet>
</comment>
</object>
<script type="text/javascript">
<!--
function getSize()
{
var windowWidth,windowHeight;
if(window.innerWidth){
windowWidth=window.innerWidth;
} else if(document.documentElement && document.documentElement.clientWidth){
windowWidth=document.documentElement.clientWidth;
} else if(document.body){
windowWidth=document.body.clientWidth;
}
if(window.innerHeight){
windowHeight=window.innerHeight;
} else if(document.documentElement && document.documentElement.clientHeight){
windowHeight=document.documentElement.clientHeight;
} else if(document.body){
windowHeight=document.body.clientHeight;
}
var oApplet=document.getElementById("ExampleApplet");
oApplet.height=windowHeight;
oApplet.width=windowWidth;
}
getSize();
window.οnresize=getSize;
//-->
</script>
</body>
</html>
ExampleApplet.java:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.HeadlessException;
public class ExampleApplet extends Applet {
public ExampleApplet() throws HeadlessException{
super();
}
public void paint(Graphics g){
g.drawString(getWidth()+" : "+getHeight(),20,20);
}
}
JAVASCRIPT动态设置applet窗口大小(转)
最新推荐文章于 2017-01-17 20:41:00 发布