Click to See Complete Forum and Search --> : Automatic focus to Java applet


mknutsson
10-17-2003, 07:39 AM
Is there any JavaScript code that automatically sets focus to a Java applet in a new window?

Problem is that when creating a new browser window with a Java applet in it, the applet doesn't get focus automatically. You have to klick on it with mouse first.

I have tried the focus() method, but that doesn't work since the applet isn't fully loaded when the web page is loaded.

Or...

Should the APPLET contain code that automatically focuses it? I have tried, but failed there as well.

Anyone who knows?

Thanks.

fredmv
10-19-2003, 06:35 PM
Inside the document that contains the applet use the following code in the <head> section:<script type="text/javascript">
onload = function()
{
document.getElementsByTagName( "applet" )[0].focus();
}
</script>I hope that helps you out.

mknutsson
10-21-2003, 12:54 AM
A solution is present here: <http://forum.java.sun.com/thread.jsp?forum=421&thread=361104&start=0&range=15#2095069>

Code to request focus is inserted in the APPLET.