您的位置:首页 > 移动开发

JAVASCRIPT动态设置applet窗口大小(转)

2009-04-15 14:10 435 查看
下面的脚本能准确获取大部分浏览器的窗口大小。
代码如下:
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.onresize=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);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: