使用deployJava.runApplet来定位特定元素

Gre*_*tit 6 javascript css java applet

经过多年成功维护使用旧版本的applet:

<script src="foo.js"></script> 
Run Code Online (Sandbox Code Playgroud)

嵌入Java小程序的方法,我们无法掩盖我们的耳朵并唱"La la la!" 了.

是时候使用:

deployJava.runApplet()
Run Code Online (Sandbox Code Playgroud)

当我使用单击处理程序触发此方法时(此处通过jQuery在按钮上使用事件侦听器,但无关紧要):

$('#button').click(function() {
  deployJava.runApplet(attributes, parameters, version);
});
Run Code Online (Sandbox Code Playgroud)

...它会清除整个现有文档并将其替换为applet.我需要知道的是如何将特定的DOM元素作为applet的容器​​,这样我的页面就不会被擦除.

看起来它是一个我可以以target: someElement"someElement"是DOM对象或元素ID作为字符串的形式传递的属性.但是,我找不到这种属性的文档.

为了完成,以下是通过的内容:

/*here is where I imagine there might be an applicable attribute */
var attributes = {
  name: "SomeName",
  code: "some.class",
  archive: "some.jar",
  width: 640,
  height: 400
};

var parameters = {
  someParameter: someValue
};

var version = "1.5";
Run Code Online (Sandbox Code Playgroud)

我可以获得document.write重建文档所需的一切,但我相信你们都可以想象这个潜在客户在我看来是多么可怕.

任何指针都将非常感激.

小智 6

作为Christophe Roussy解决方案的替代方案,您可以document.write在跑步时覆盖deployJava.runApplet.

像这样:

function docWriteWrapper(func) {
    var writeTo = document.createElement('del'),
        oldwrite = document.write,
        content = '';
    writeTo.id = "me";
    document.write = function(text) {
        content += text;
    }
    func();
    writeTo.innerHTML += content;
    document.write = oldwrite;
    document.body.appendChild(writeTo);
}
Run Code Online (Sandbox Code Playgroud)

那么:

docWriteWrapper(function () {
    deployJava.runApplet(attributes, parameters, "1.6");
});
Run Code Online (Sandbox Code Playgroud)

有点hackish但有点像魅力;)