Question

I have error with calling requestFocus() method in JS.

Uncaught TypeError: Object #<HTMLAppletElement> has no method 'requestFocus'

This is my JS code between <head> tags

function onLoad() {
    var attributes = {
        'id': 'Client',
        'archive': 'client.jar',
        'code': 'org.kuzy.client.ui.Applet.class',
        'width': '100%',
        'height': '100%'
    };

    var parameters = {
        'scriptable': 'true'
    };

    deployJava.runApplet(attributes, parameters);

    window.onfocus = function() {
        document.getElementById("Client").requestFocus();
    };
}

There is one strange feature, when I run the code in debug in chrome, everything works fine. I hope for your advice.

Was it helpful?

Solution

I'm not sure, but probably when you invokes the method requestFocus() applet is not already loaded. Probably when you are debugging you are stopping js execution and you are giving enough time to the applet to be loaded. So probably you need a callback or some mechanism in order to know when applet is ready.

OTHER TIPS

This entire method has a 'bad code' smell to it.

  1. The deployJava.runApplet(attributes, parameters); call should be in the page body, and called as soon as the page is written.
  2. The function onLoad() though, should logically be defined in the document head.
  3. By the time of the onLoad call, the applet should at least be loading, and might even be loaded ready for use. Note that the onload event is fired when the page, the scripts, styles and images are downloaded. But it does not cover downloads that are handled by the JVM (e.g. the Jars of the applet or its media resources).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top