使用 javascript 调用 Applet.getMethod() 会抛出错误消息:TypeError: Applet.getMethod() is not a function [英] Call Applet.getMethod() with javascript throws error msg : TypeError: Applet.getMethod() is not a function
问题描述
我有一个使用 JMF 库的小程序,如下所示:
I have an applet that use JMF libraries, called like this :
<object id="cameraViewer"
classid="java:MyApplet.class"
type="application/x-java-applet"
archive="myapplet.jar" height="197" width="159"
align="middle" codebase=".">
<param name="code"
value="MyApplet" />
<param NAME="MAYSCRIPT" VALUE="true" />
<param name="appletWidth" value="250" />
<param name="appletHeight" value="200" />
<param name="archive" value="myapplet.jar" />
<param name="JAVA_CODEBASE" value="." />
<font color="red">Applet error</font>
</object>
然后我调用一个javascript函数:
then I call a javascript function :
var cameraViewer = document.getElementById('cameraViewer');
var deviceList = new Array(cameraViewer.listDevices());
在javascript代码的第二行,javascript控制台抛出错误(TypeError: cameraViewer.listDevices is not a function).
In the second line of javascript code, an error is thrown in javascript console (TypeError: cameraViewer.listDevices is not a function).
仅当我在 Firefox 8.0.1 上使用 Windows 7 时才会抛出此问题
this problem is thrown only when I use Windows 7 with Firefox 8.0.1
因为此代码适用于:
- Windows 7 和 Chrome
- Windows 7 和 Firefox 20
- Windows XP 和 Firefox 8.0.1
你对这个问题有什么想法吗!!?
Have you any Idea about this problem !!?
推荐答案
我认为您正在尝试在函数尚未加载时调用该函数(浏览器在小程序加载时的行为不同,有些是同步加载的,有些则没有).
i think you are trying to call the function whilst it's still not loaded yet (browsers behave differentely on applet loading, some load it synchronously while other don't).
在尝试调用该函数之前检查该函数是否存在会更安全,如果不存在,请告诉浏览器等待几毫秒.
it would be safer for you to check if the function exists before trying to call it , in case it doesn't , tell the browser to wait a few milli seconds .
这是给你的模拟代码:
var cameraViewer = document.getElementById('cameraViewer');
if (typeof(cameraViewer.listDevices) != "undefined") {
// safe to use the function
var deviceList = new Array(cameraViewer.listDevices());
}
else{
setTimeout(function() {
var deviceList = new Array(cameraViewer.listDevices());
}, 1000);
}
这篇关于使用 javascript 调用 Applet.getMethod() 会抛出错误消息:TypeError: Applet.getMethod() is not a function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!