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);
}
}
代码如下:
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);
}
}
相关文章推荐
- yui cookie Dynamically Change Text Size Using Javascript 动态设置字体大小,写入Cookie
- JavaScript动态修改弹出窗口大小的方法
- 3.1 Javascript:探索客户端-设置网页元素根据窗口比例调整位置与大小
- javascript中对窗口大小,文本等的设置
- javascript在不同浏览器设置窗口高度、宽度,改变窗口大小
- 通过窗口大小适时调整以及子窗口的动态布局来解决窗口在不同DPI设置下的显示问题
- Javascript获取和设置窗口大小
- javascript动态改变窗口大小
- Javascript 动态编程--动态设置网页元素是否可见,是否可用,改变大小,动态插入文字,进度条,动态改变背景例子
- Android——动态设置TextView CompoundDrawable的大小
- Android程序中代码动态设置Textview文字的大小解决px转dp的问题
- 【javascript脚本】动态设置div的高度和宽带
- IE和FF下javascript获取网页及窗口大小的区别
- 用 javascript 控制浏览器窗口大小
- Javascript获取各种浏览器可见窗口大小
- SetConsoleWindowInfo 函数--设置控制台窗口的大小和位置
- webview动态设置浏览字体大小
- Echarts 如何设置多个图表自适应窗口大小
- Ext3.2.2 表格随窗口改变动态适应窗体大小
- npoi的用法,动态的判断单元格的大小,设置列的宽度