使用deployJava.runApplet针对特定的元素 [英] Using deployJava.runApplet to target specific element
问题描述
经过多年的成功维护,使用好老的小程序:
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元素是applet的容器,让我的网页不会被抹去。
...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.
看起来这将是一个属性,我可以传递的形式目标: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";
我能文件撰写
的一切,我需要重建的文件,但我敢肯定,你都可以想像多么可怕的这种前景似乎给我。
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.
任何指针将大大AP preciated。
Any pointers would be greatly appreciated.
推荐答案
作为替代<一个href=\"http://stackoverflow.com/questions/13517790/using-deployjava-runapplet-to-target-specific-element?answertab=active#answer-15139480\">Christophe鲁西解决方案,您可以覆盖文件撰写
运行时 deployJava.runApplet
。
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屋!