Call Applet.getMethod() with javascript throws error msg : TypeError: Applet.getMethod() is not a function

ぐ巨炮叔叔 提交于 2019-12-11 05:33:18

问题


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>

then I call a javascript function :

var cameraViewer = document.getElementById('cameraViewer');
var deviceList = new Array(cameraViewer.listDevices());

In the second line of javascript code, an error is thrown in javascript console (TypeError: cameraViewer.listDevices is not a function).

this problem is thrown only when I use Windows 7 with Firefox 8.0.1

Because this code works fine with :

  • Windows 7 and Chrome
  • Windows 7 and Firefox 20
  • Windows XP and Firefox 8.0.1

Have you any Idea about this problem !!?


回答1:


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 .

here's a mock code for you:

    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);
}


来源:https://stackoverflow.com/questions/16298597/call-applet-getmethod-with-javascript-throws-error-msg-typeerror-applet-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!