By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

Detecting .class file

P: n/a
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.

Thanks.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Thomas Magma" <kh*****@beer.com> schreef in bericht
news:U8NEb.753982$6C4.689918@pd7tw1no...
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.getElementById('appletID');
try {
// Try calling one of the applet's methods
applet.some_method();
} catch (e) {
applet.style.display = 'none';
}
}
JW

Jul 20 '05 #2

P: n/a


Janwillem Borleffs wrote:
"Thomas Magma" <kh*****@beer.com> schreef in bericht
news:U8NEb.753982$6C4.689918@pd7tw1no...
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.getElementById('appletID');
try {
// Try calling one of the applet's methods
applet.some_method();
} catch (e) {
applet.style.display = '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 hideAppletsNotRunning () {
for (var i = 0; i < document.applets.length; i++) {
var applet = document.applets[i];
if (typeof applet.isActive == 'undefined') {
if (applet.style) {
applet.style.display = 'none';
}
}
}
}

window.onload = hideAppletsNotRunning;
</script>
</head>
<body>
<div>
<p>
Is the applet visible?
<applet name="appletName" 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/

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.