1

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 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer that gave me an idea to use a sleep method. So in my case I encourated the problem with try catch block, and when catching the exception I re-call my function after somme milliseconds with (setTimeout method).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.