我有一個java小程序是嵌入在HTML使用object-comment-embed
方法。我想在調整瀏覽器窗口大小時調整applet的大小。我在互聯網上找到了解決方案,但它們都是基於已棄用的applet
標籤工作。如何在瀏覽器調整大小時調整java applet的大小?
此外,在FireBug中的embed
元素上嘗試setSize()
調用時,它將調整applet的內容大小,但不調整applet視口的大小。也就是說,顯示給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>
您的調整大小函數被調用? (例如,到目前爲止,錯誤在哪裏?) – scunliffe 2008-12-17 17:06:02