我想通过一个JavaScript函数,在按钮按下时动态地将Java小程序插入到网页中。 (在页面加载时加载小程序会导致速度变慢,冻结浏览器等等...)我正在使用以下代码,在Firefox中无缝运行,但在IE8、Safari 4和Chrome中失败而没有显示错误消息。有人知道为什么这不像预期的那样工作,并且如何以一种适用于所有浏览器的方式动态地插入小程序吗? 我尝试过使用document.write()
,如其他地方所建议的,但在页面加载后调用它会导致页面被抹掉,因此对我来说这不是一个选项。
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);
}