[英]Call JAVA applet method from JavaScript, IE/FF object/embed issue
I'm using JavaScript to access methods inside a JAVA applet. 我正在使用JavaScript来访问JAVA小程序中的方法。
The applet is embedded into the HTML page this way: 小程序通过以下方式嵌入到HTML页面中:
<object
class="cn" id="testapplet-object"
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="300" height="300"
codebase="http://java.sun.com/update/1.6.0/jinstall-6u30-windows-i586.cab#Version=1,6,0,0">
<param name="archive" value="TestCom.jar" />
<param name="code" value="TestCom.class" />
<param name="scriptable" value="true" />
<param name="mayscript" value="mayscript" />
<embed class="cn" id="testapplet-embed"
type="application/x-java-applet;version=1.6"
width="300" height="300"
archive="TestCom.jar"
code="TestCom.class"
pluginspage="http://java.com/download/"
myParam="My Param Value",
mayscript="mayscript" />
</embed>
</object>
Under this applet there is a button and the code related to the button is the following: 在此小程序下有一个按钮,与该按钮相关的代码如下:
var applet = document.getElementById("testapplet-object");
var btn = document.getElementById("btn");
btn.addEventListener("click",function(){
applet.callAppletMethod();
});
Problem is: this code only works in IE. 问题是:此代码仅在IE中有效。 To make it work in Firefox I must pass "testapplet-embed" to getElementById (but then it won't work in IE). 为了使其能够在Firefox中工作,我必须将“ testapplet-embed”传递给getElementById(但随后在IE中将无法工作)。
Is there any crossbrowser way to declare my applet variable? 有什么跨浏览器方法来声明我的applet变量?
Use deployJava.js. 使用deployJava.js。 https://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html https://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
var attributes = {
id:'testapplet',
archive:"TestCom.jar",
code:"TestCom"
code:'jstojava.MathApplet',
width:300, height:300
};
var parameters = {} ;
deployJava.runApplet(attributes, parameters, '1.6');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.