faqts : Computers : Programming : Languages : JavaScript : Applets/Java

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 11 people (64%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I detect that the applet have been closed in the javascript.

Oct 30th, 2001 03:22
Jean-Bernard Valentaten, Ted Ibsonius,


First of all you have to make sure, that the applet-tag includes the 
mayscript-parameter (e.g. <applet codebase="./" archive="myApp.jar" 
mayscript>)
Then the followin code will only work with browsers that do not use the 
Java-Plugin (IE and NN 4.x, NN6 won't work!!!).
To check whether an applet is running or not, you need to declare your 
thread as public (you're using threads, aren't you!!! you'd better), so 
that it can be read by any class (or js-code) that is external.
Now all you have to do, is check that threads' status (let's say your 
applet is reachable by the object myApplet, that has been declared in 
js, and that thread is called myThread)
function isAppletRunning()
{
  if (!myApplet.myThread) alert("Applet not running");
  else alert("Applet is running!");
}
That ought to do the trick. The trick behind that, is that if your 
applet is stopped (or has stopped), the thread object still exists, but 
is null. Since null is beeing false when seen as a boolean-expression, 
this function should work.
HTH
Jean