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.
java applet requestFocus() method error when called in js
-
12-10-2022 - |
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.
La solution
Autres conseils
This entire method has a 'bad code' smell to it.
- The
deployJava.runApplet(attributes, parameters);
call should be in the page body, and called as soon as the page is written. - The
function onLoad()
though, should logically be defined in the document head. - By the time of the
onLoad
call, the applet should at least be loading, and might even be loaded ready for use. Note that theonload
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).
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow