有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javascript加载Java小程序,高度设置为100%

我有一个显示java小程序的网页。如果使用JavaScript调整窗口的大小,则小程序的大小会调整,JavaScript工作正常。 小程序的宽度和高度设置为100%。加载小程序时,将显示一个图像

image = "preloader.gif"

使用IE 6/7,一切正常。但在Firefox中,小程序的高度约为200像素。宽度在100%时是正确的。因此,预加载程序图像被切成两半。加载小程序并且javascript调整页面大小后,正确设置宽度和高度

如果更改HTML代码并为小程序使用固定大小,则在加载过程中对象显示正确,但之后无法调整大小

这个问题有什么解决办法吗

谢谢, 丹尼尔

ps我使用的是Object/embed标记,但是如果我使用applet标记,问题是相同的


共 (4) 个答案

  1. # 1 楼答案

    我也有同样的问题,我找不到答案,但我找到了解决办法。 您必须将小程序代码嵌入Javascript函数中,并在加载页面后不久将其填充到正文的innerHtml中(或在任何您想使用小程序的地方)。所以

    //optional: add styles
    function styleApplet(){
        document.getElementsByTagName('body')[0].style.overflow = 'hidden';
    }
    
    //complementary funcion so applet code is readable
    function documentWrite(chars){
        buffer +=chars;
    }
    
    //funcion to add all code at once. It is compulsory
    function executeWrite(){
        document.getElementsByTagName('body')[0].innerHTML = buffer;
        buffer = '';
    }
    
    function writeApplet(){
        documentWrite('<applet code="..... </applet>');
        documentWrite('..... ');
        documentWrite('</applet>');
    
        executeWrite();
    }
    
    $(document).ready(function(){
        setTimeout('writeApplet()',100);
        setTimeout('styleApplet()',100); //optional
    }
    

    对答案的任何补充都有帮助:-)

  2. # 2 楼答案

    我建议您实现一个基于CSS的解决方案,并创建大小为100%的小程序。我使用这种方法,它简单,可靠,跨浏览器。你有什么理由不能这样做吗

  3. # 3 楼答案

    不看这一页很难说。一种可能是在javascript运行之前加载小程序。在这种情况下,您可以尝试使用javascript加载小程序(而不是直接在html中进行编码)

  4. # 4 楼答案

    我在Firefox和Opera中得到了同样的短而宽的applet

    现在,我动态创建小程序,这允许我根据视口大小计算其包含div的大小。这让我相信,如果您使用的包含div的大小是以点为单位指定的,而不是以100%为单位,那么您将得到您想要的

    我用来创建小程序的代码

    function initJavaView() {
        ...
        var viewportHeight = window.innerHeight ? window.innerHeight : 
                                                  $(window).height(); 
        var height = viewportHeight - appletArea.offsetTop - 8;
        html = '<div style="width:100%;height:' + height + 'px;">'
    
        if (!$.browser.msie /*&& !$.browser.mozilla*/){
            html = html + '<object type="application/x-java-applet;version=1.5" ';
        } else {
            html = html +
                '<object ' +
                'classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" '+
                'codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=1,5,0,0" ';
        }
        html = html + ' width="100%" height="100%">' +
        ...
        appletArea.innerHTML = html;
    };
    

    http://books.verg.es/elements_of_ux.html?format=java运行的代码