Janwillem Borleffs wrote:
"Thomas Magma" <kh*****@beer.c om> schreef in bericht
news:U8NEb.7539 82$6C4.689918@p d7tw1no...
Hello,
I have a case where an applet .class file may or may not be present. In
the
case when it is not present I get a big gray box where the applet is
suppose
to be. This is understandable, but undesirable when someone is viewing or
printing the page. Is there a way to test first if the .class file is
present before hand in order to avoid the big gray box.
When the applet contains public methods which are accessible with
javascript, you could try the following:
window.onload = function () {
var applet = document.getEle mentById('apple tID');
try {
// Try calling one of the applet's methods
applet.some_met hod();
} catch (e) {
applet.style.di splay = 'none';
}
}
That seems to be a good idea, only that you don't need some_method and
the try/catch, any applet extends the Applet class and thus should have
the public method isActive which you could check for with typeof.
I have tried the following with Netscape 7.1, IE6, and Opera 7 and the
applet (whose class file doesn't exist) is indeed hidden:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>applet test</title>
<script type="text/javascript">
function hideAppletsNotR unning () {
for (var i = 0; i < document.applet s.length; i++) {
var applet = document.applet s[i];
if (typeof applet.isActive == 'undefined') {
if (applet.style) {
applet.style.di splay = 'none';
}
}
}
}
window.onload = hideAppletsNotR unning;
</script>
</head>
<body>
<div>
<p>
Is the applet visible?
<applet name="appletNam e" code="anApplet. class" width="200" height="200">
</applet>
</p>
</div>
</body>
</html>
The only problem I see with that approach is that some browsers might
well run applets while not supporting LiveConnect (scripting access from
JavaScript to the applet's members) and then the above example would
hide a running applet as it exposes no methods.
--
Martin Honnen
http://JavaScript.FAQTs.com/