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

来源:互联网 发布:qq三国50js装备满属性 编辑:程序博客网 时间:2024/04/30 13:20

 下面的脚本能准确获取大部分浏览器的窗口大小。
代码如下:
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);
        }
}

原创粉丝点击