gpt4 book ai didi

java - 如何在调整浏览器大小时调整 java applet 的大小?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:52:30 25 4
gpt4 key购买 nike

我有一个使用 object-comment-embed 方法嵌入到 html 中的 java applet。每当调整浏览器窗口大小时,我都想调整小程序的大小。我在 Internet 上找到了解决方案,但它们都基于已弃用的 applet 标记。

此外,当尝试在 FireBug 中对我的 embed 元素调用 setSize() 时,它会调整小程序内容的大小,但不会调整小程序视口(viewport)的大小。也就是交给java的显示区域是不变的。

当前代码看起来像这样:

<object
id='MyApplet1'
width='300' height='200'
classid='clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
codebase='http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab#Version=1,6,0,0'>
<param name='type' value='application/x-java-applet;version=1.6'>
<param name='scriptable' value='false'>
<param name='codebase' value='foo'>
<param name='code' value='bar'>
<param name='archive' value='baz'>
<param name='arg1' value='A'>
<param name='arg2' value='B'>
<comment>
<embed
id='MyApplet2'
width='300' height='200'
pluginspage='http://java.sun.com/products/plugin/index.html#download'
type='application/x-java-applet;version=1.6'
scriptable='false'
codebase='foo'
code='bar'
archive='baz'
arg1='A'
arg2='B'>
<noembed>
</noembed>
</embed>
</comment>
</object>
<script type="text/javascript">
function resize() {
min_width = 300;
min_height = 200;
frame_width = 0;
frame_height = 0;
if(parseInt(navigator.appVersion) > 3) {
if(navigator.appName=='Netscape') {
frame_width = window.innerWidth;
frame_height = window.innerHeight;
}
if (navigator.appName.indexOf('Microsoft') != -1) {
frame_width = document.body.offsetWidth;
frame_height = document.body.offsetHeight;
}
}
frame_width *= 0.78;
frame_height *= 0.78;
applet_width = frame_width > min_width ? frame_width : min_width;
applet_height = frame_height > min_height ? frame_height : min_height;
document.getElementById('MyApplet1').setSize(applet_width, applet_height);
document.getElementById('MyApplet2').setSize(applet_width, applet_height);
}
window.onResize = resize;
window.onLoad = resize;
</script>

最佳答案

尝试替换这些行:

document.getElementById('MyApplet1').setSize(applet_width, applet_height);
document.getElementById('MyApplet2').setSize(applet_width, applet_height);

与:

document.getElementById('MyApplet1').style.height = applet_height + "px";
document.getElementById('MyApplet1').style.width = applet_width + "px";

document.getElementById('MyApplet2').style.height = applet_height + "px";
document.getElementById('MyApplet2').style.width = applet_width + "px";

关于java - 如何在调整浏览器大小时调整 java applet 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/375252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com