我已将以下小程序标记转换为对象标记,以便它可以工作。但由于某种原因,下面的内容不起作用。首先,下面的转换是否正确?
小程序:
document.writeln('<applet');
document.writeln(' code="LittleShootApplet"');
document.writeln(' id="LittleShootApplet" name="LittleShootApplet"');
document.writeln(' scriptable="true"');
document.writeln(' mayscript="true"');
document.writeln(' height="0" width="0"');
document.writeln(' style="xdisplay: none; width:0; height:0; padding:0; margin:0;" >');
document.writeln('</applet>');
对象:
document.writeln('<OBJECT ');
document.writeln('classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0">');
document.writeln('<PARAM name="code" value="LittleShootApplet">');
document.writeln('<PARAM name="id" value="LittleShootApplet">');
document.writeln('<PARAM name="scriptable" value="true">');
document.writeln('<PARAM name="mayscript" value="true">');
document.writeln('<PARAM name="style" value="xdisplay: none; width:0; height:0; padding:0; margin:0;">');
document.writeln('</OBJECT>');
顺便说一句,我正在使用 JavaScript 将以上内容写入页面。
我在页面上有一个按钮,尝试使用 JavaScript 调用 Java Applet 函数,但收到此错误。
Message: 'document.LittleShootApplet' is null or not an object
Line: 77
Char: 1
Code: 0
URI: http://localhost/webs/front-end/activity.php
上述 Javascript 在从 Java 小程序调用函数时遇到问题,因为该小程序尚未正确加载。
感谢大家的帮助。
最佳答案
将 ID 和 Name 属性直接添加到 object
标记中,而不是作为 param
的:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0"
id="LittleShootApplet" name="LittleShootApplet">
...
</OBJECT>
删除了 document.write 以提高可读性。
我建议您通过 ID 获取元素,而不是通过 document.elementName
:
var applet = document.getElementById('LittleShootApplet');
// instead of document.LittleShootApplet
关于java - 将 APPLET 标签转换为 IE6 的 OBJECT 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1902317/