简体   繁体   中英

Detect when an Applet is ready for use

I'm using this technique to detect when the current tab gains focus and this one to set focus on the <applet> , however I get a couple of errors since the applet isn't ready when the first onFocus occurs during page-load. It doesn't appear to stop anything working but errors are not ideal!

In a perfect world I'd only set the focus handlers once the applet is ready. Alternatively the focus handler would check the applet is valid before 'touching' it... either is fine depending on which is simpler. Non-jQuery answers preferred please!

My HTML looks like:

<head>
<script language="javascript">
function focusIn()
{
    document.myApplet.requestFocus();
}
if ("onfocusin" in document)
    document.onfocusin = focusIn;
else
    window.onfocus= focusIn;
</script>
</head>

At the end of the Applet.start() method, call a JS function to indicate 'applet is ready'. The applet might even be able to detect a tab change to the applet page or the browser being restored from minimized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM