1

我有一个div加载 Java 小程序的地方,但是新版本的 Java 给出了一个未签名的证书错误:

错误

我想知道我是否可以限制加载DeployJava.RunApplet当前在加载页面时实例化的 Java 小程序 (),仅在用户单击“ 3D 视图”按钮时加载?

小程序加载代码:

<div id="appletContainer" runat="server" style="width:(document.body.clientWidth - 270);height:300" clientidmode="Static">
    <script type="text/javascript">
        var showCI = 0;
        if (document.getElementById("hdnHas3D").value == "1" && !isAppleMobile()) {
            var J3DStyleID = document.getElementById("hdn3DStyleID").value;
            var code = "com.wirefusion.player.AppletPlayer";
            var archiveList = "Some achive List";
            var width = document.body.clientWidth - 270;
            var height = 300;

            var attributes = {
                id: "appletContainerX",
                name: J3DStyleID,
                code: code,
                codebase: ".",
                width: width,
                height: height,
                mayscript: "true"
            };
            var parameters = {
                progressFunc: "handleAppletProgress",
                archive: archiveList,
                java_arguments: "-Xmx200m",
                regid: "6050-25",
                resourcefolder: "/RichContent/3D_Vehicles/J3D/Vehicles/" + J3DStyleID + "/",
                preloadfile: J3DStyleID + ".jar",
                environmentType: "WEBSITE",
                environmentWidth: width,
                environmentHeight: height,
                groupsXMLFile: "../../Resources/groups.xml",
                vehicleXMLFile: J3DStyleID + ".xml"
            };
            var version = '1.6.0_20';
            if (deployJava.versionCheck(version + '+')) {
                docWriteWrapper(function () {
                    deployJava.runApplet(attributes, parameters, version);
                });
            } else {
                if (document.getElementById("iframeContainer").style.display != "none") {
                    alert("Unable to load Interactive mode");
                    showCI = 1;

                }
            }
        }
    </script>
</div>
4

1 回答 1

4

不要在 HTML 中包含常规<applet>(或<object>)标记。相反,请按照本教程 了解如何使用 JavaScript 将其动态添加到您的页面。

HTML 4

function loadApplet(code,codebase,width,height,alt){
    var placeholder=document.getElementById('placeholder');
    if(window.opera){
        placeholder.innerHTML='<applet code="'+code+'" codebase="'+codebase+'" width="'+width+'" height="'+height+'" alt="'+alt+'"></applet>';
    }else{
        var a=document.createElement('applet');
        a.setAttribute('code',code);
        a.setAttribute('codebase',codebase);
        a.setAttribute('width',width);
        a.setAttribute('height',height);
        a.setAttribute('alt',alt);
        placeholder.appendChild(a);
    }
}

HTML 5

function loadApplet(code,codebase,width,height,alt){
    var placeholder=document.getElementById('placeholder');
    var a = document.createElement('object');
    a.setAttribute('type','application/x-java-applet');
    a.setAttribute('width',width);
    a.setAttribute('height',height);
    a.setAttribute('alt',alt);
    
    var codeParam = document.createElement('param');
    codeParam.setAttribute('name','code');
    codeParam.setAttribute('value',code);
    a.appendChild(codeParam);

    var codebaseParam = document.createElement('param');
    codebaseParam.setAttribute('name','codebase');
    codebaseParam.setAttribute('value',codebase);
    a.appendChild(codebaseParam);

    placeholder.appendChild(a);
}

在您的 HTML 中创建一个占位符DIV,即您希望将其加载到的位置,以及一个用于加载您的小程序的链接。您需要将加载链接中的值自定义为 Applet 的值。

<div id="placeholder"></div>
<input type="button" value="Load Applet" onclick="loadApplet('TestApplet.class','.','200','300','demo applet')" />

链接的教程解释了更多关于如何使它漂亮的信息。上面的代码只是简单的概念。


自修改问题以来的更新

您的代码似乎已经使用 JavaScript 加载小程序。问题是脚本在页面加载后立即运行,而不是在用户单击“ 3D 视图”按钮时运行。

为了防止它立即运行,您可以将加载程序代码包装在一个名为loadApplet. 所以用伪代码解释:

function loadApplet() {
    // Your existing applet loading code
}

所以使用你包含的源代码,我用一个函数包装了它,这将阻止它在你的页面加载时运行。

<div id="appletContainer" runat="server" style="width:(document.body.clientWidth - 270);height:300" clientidmode="Static">
    <script type="text/javascript">
        // Wrap your code with a function called loadApplet
        function loadApplet() {
            // Your applet loading code:
            var showCI = 0;                                        
            if (document.getElementById("hdnHas3D").value == "1" && !isAppleMobile()) {
                var J3DStyleID = document.getElementById("hdn3DStyleID").value;
                var code = "com.wirefusion.player.AppletPlayer";
                var archiveList = "Some achive List";                                         
                var width = document.body.clientWidth - 270;
                var height = 300; 

                var attributes = {
                    id: "appletContainerX",
                    name: J3DStyleID,
                    code: code,
                    codebase: ".",
                    width: width,
                    height: height,
                    mayscript: "true"
                };
                var parameters = {
                    progressFunc: "handleAppletProgress",
                    archive: archiveList,
                    java_arguments: "-Xmx200m",
                    regid: "6050-25",                                                
                    resourcefolder: "/RichContent/3D_Vehicles/J3D/Vehicles/" + J3DStyleID + "/",
                    preloadfile: J3DStyleID + ".jar",
                    environmentType: "WEBSITE",
                    environmentWidth: width,
                    environmentHeight: height,
                    groupsXMLFile: "../../Resources/groups.xml",
                    vehicleXMLFile: J3DStyleID + ".xml"
                };
                var version = '1.6.0_20'; 
                if (deployJava.versionCheck(version + '+')) {
                    docWriteWrapper(function () {
                        deployJava.runApplet(attributes, parameters, version);
                    });                                               
                } else {
                    if (document.getElementById("iframeContainer").style.display != "none") {
                        alert("Unable to load Interactive mode");
                        showCI = 1;

                    }
                }
            }

        }
    </script>
</div>

然后到您的 3D 视图元素中,您必须添加一个调用该函数的onclick属性。loadApplet()例如:

<input type="button" value="Show in 3D" onclick="loadApplet()" />

注意:在这种情况下,您的 3D 视图按钮可能已经有一个onclick属性连接到使您的小程序进入视图的函数,在这种情况下,您仍然希望在加载函数之后调用它。我用showApplet()了一个例子,这对你来说很可能是不同的。

<input type="button" value="Show in 3D" onclick="loadApplet(); showApplet();" />

如果您提供“ 3D 显示”按钮的代码,我可以在这里为您提供更好的帮助。

于 2013-06-03T08:19:20.670 回答