使用 deployJava.runApplet 定位特定元素 [英] Using deployJava.runApplet to target specific element

查看:28
本文介绍了使用 deployJava.runApplet 定位特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在成功维护一个使用旧的小程序多年后:

After many years of successfully maintaining an applet that uses the good old:

<script src="foo.js"></script> 

嵌入Java小程序的方法,我们无法捂着耳朵唱啦啦啦!"了.

method of embedding a Java applet, we're unable to cover our ears and sing "La la la!" anymore.

是时候使用了:

deployJava.runApplet()

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

When I fire this method using a click handler (here using an event listener on a button via jQuery, but it doesn't matter):

$('#button').click(function() {
  deployJava.runApplet(attributes, parameters, version);
});

...它会清除整个现有文档并用小程序替换它.我只需要知道如何将特定 DOM 元素定位为小程序的容器,这样我的页面就不会被擦除.

...it wipes out the entire existing document and replaces it with the applet. All I need to know is how to target a specific DOM element to be the container for the applet, so that my page doesn't get wiped.

这似乎是一个我可以以 target: someElement 形式传递的属性,其中someElement"是一个 DOM 对象或作为字符串的元素 ID.但可惜,我找不到此类属性的文档.

It seems like it would be an attribute I could pass in the form of target: someElement where "someElement" is either a DOM object or the element's ID as a string. But alas, I can't find documentation for such an attribute.

为了完整起见,这里是传递的内容:

For the sake of being complete, here's what's being passed:

/*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";

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

I can document.write everything I need to rebuild a document, but I'm sure you can all well imagine how hideous that prospect seems to me.

任何指针将不胜感激.

推荐答案

作为 Christophe Roussy 解决方案,您可以在运行 deployJava.runApplet 时覆盖 document.write.

As alternative to Christophe Roussy solution you may override document.write while running 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);
}

然后:

docWriteWrapper(function () {
    deployJava.runApplet(attributes, parameters, "1.6");
});

有点hackish,但很有魅力;)

A little bit hackish but works like a charm;)

这篇关于使用 deployJava.runApplet 定位特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆