Wednesday 28 August 2013

How can I test that a java applet is loaded using javascript?

How can I test that a java applet is loaded using javascript?

pThe applet is my own, calling ready() simply returns yes./p pFirst I
tried embedding the applet like this:/p precode lt;object id=appletIe
classid=clsid:8AD9C840-044E-11D1-B3E9-00805F499D93 width=100% height=100%
codebase=MyApplet.jargt; lt;param name=archive value=MyApplet.jar /gt;
lt;param name=code value=MyPackage.Myclass /gt; lt;param name=myParam
value=My Param Value /gt; lt;embed id=applet MAYSCRIPT=true
type=application/x-java-applet;version=1.6 width=1px height=1px
archive=MyApplet.jar code=MyPackage.Myclass
pluginspage=http://java.com/download/gt; lt;/objectgt; /code/pre pI tried
to check it was loaded with javascript by calling ready() on
document.ready like this: but I immediately got an error (TypeError:
$(...).get(...).ready is not a function) so I assume it tried to call the
applet ready() function before it loaded./p precode$(function(){ if
(CheckApplet() == false) { $('#appletStatus').html('Failed to load
applet.'); } }); function CheckApplet() { return
$('#applet').get(0).ready() == 'yes'; } /code/pre pThen I tried loading
the applet with jquery like this:/p pThis worked a little better, it did
not call the applet ready() function until the applet had loaded. But once
in a while it doesn't work, the javascript becomes unresponsive, no error
is produced even though the applet seems to be loaded ok./p precode
$(function(){ var html = ''; if ($.browser.msie) { html += 'lt;object
id=applet '; html += 'classid=clsid:8AD9C840-044E-11D1-B3E9-00805F499D93
'; html += 'width=100% height=100% '; html += 'codebase=MyApplet.jargt; ';
html += 'lt;param name=archive value=MyApplet.jar /gt; '; html +=
'lt;param name=code value=MyPackage.Myclass /gt; '; html += 'lt;param
name=myParam value=My Param Value /gt; '; html += 'lt; /objectgt;'; } else
{ html += 'lt;embed id=applet'; html +=
'type=application/x-java-applet;version=1.6'; html += 'width=1px
height=1px '; html += 'archive=MyApplet.jar'; html +=
'code=MyPackage.Myclass '; html +=
'pluginspage=http://java.com/download/'; html += 'myParam=My Param Value
/gt;'; html += 'lt;/embedgt;'; } $('#myDiv').append(html); if
(CheckApplet() == false) { $('#appletStatus').html('Failed to load
applet.'); } }); /code/pre pI'm looking for suggestions on how I can
improve this, or other ways to achieve the solution./p

No comments:

Post a Comment