我如何嵌入Java程序动态使用Javascript? [英] How can I embed a Java applet dynamically with Javascript?

查看:100
本文介绍了我如何嵌入Java程序动态使用Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够插入Java小程序到网页动态使用时调用按钮pressed JavaScript函数。 (装在页面加载的小程序会减慢速度太多,冻结浏览器,等...)我使用下面的code,它在FF无缝工作,但没有在IE8,Safari 4的错误信息失败,铬。没有人有任何想法,为什么因为预计不工作,以及如何动态地插入,在所有浏览器的工作方式一个小程序?我已经尝试过使用的document.write()其他地方的建议,但调用的页面在页面加载后,结果被擦除,所以这不是一个选项我的。

 函数的createPlayer(parentElem)
{
    //农行变量声明,并在这里设置    玩家=使用document.createElement('对象');
    player.setAttribute(CLASSID,java的:TunePlayer.class);
    player.setAttribute(档案,TunePlayer.class,PlayerListener.class,abc4j.jar);
    player.setAttribute(codeTYPE,应用程序/ x-j​​ava的小程序);
    player.id =tuneplayer;
    player.setAttribute(宽,1);
    player.setAttribute(高度,1);    参数=使用document.createElement('参数');
    param.name =ABC;
    param.value = ABC;
    player.appendChild(参数);    参数=使用document.createElement('参数');
    param.name =MAYSCRIPT;
    param.value = TRUE;
    player.appendChild(参数);    parentElem.appendChild(播放器);
}


解决方案

 的document.write()

将覆盖整个文档。如果你想保留的文件,只是想补充一个小程序,你需要将其追加

  VAR应用=使用document.createElement('小程序');
app.id ='Java的;
app.archive ='Java.jar';
。应用code ='的java.class;
app.width ='400';
app.height ='10';
document.getElementsByTagName('身体')[0] .appendChild(应用);

这code将添加小程序body标签的最后一个元素。确保这是在DOM处理,否则你会得到一个错误后运行。身体的OnLoad,或jQuery的准备推荐的。

I want to be able to insert a Java applet into a web page dynamically using a Javascript function that is called when a button is pressed. (Loading the applet on page load slows things down too much, freezes the browser, etc...) I am using the following code, which works seamlessly in FF, but fails without error messages in IE8, Safari 4, and Chrome. Does anyone have any idea why this doesn't work as expected, and how to dynamically insert an applet in a way that works in all browsers? I've tried using document.write() as suggested elsewhere, but calling that after the page has loaded results in the page being erased, so that isn't an option for me.

function createPlayer(parentElem)
{
    // The abc variable is declared and set here

    player = document.createElement('object');
    player.setAttribute("classid", "java:TunePlayer.class");
    player.setAttribute("archive", "TunePlayer.class,PlayerListener.class,abc4j.jar");
    player.setAttribute("codeType", "application/x-java-applet");
    player.id = "tuneplayer";
    player.setAttribute("width", 1);
    player.setAttribute("height", 1);

    param = document.createElement('param');
    param.name = "abc";
    param.value = abc;
    player.appendChild(param);

    param = document.createElement('param');
    param.name = "mayscript";
    param.value = true;
    player.appendChild(param);

    parentElem.appendChild(player);
}

解决方案

document.write()

Will overwrite your entire document. If you want to keep the document, and just want an applet added, you'll need to append it.

var app = document.createElement('applet');
app.id= 'Java';
app.archive= 'Java.jar';
app.code= 'Java.class';
app.width = '400';
app.height = '10';
document.getElementsByTagName('body')[0].appendChild(app);

This code will add the applet as the last element of the body tag. Make sure this is run after the DOM has processed or you will get an error. Body OnLoad, or jQuery ready recommended.

这篇关于我如何嵌入Java程序动态使用Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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