简体   繁体   中英

How to add new parameters to a java applet to call another method from javascript?

I am using a java applet to call Web Services. This java applet is embedded in a html web page like this:

<object classid="java:TEST3.class"
                codebase="lib/"
                type="application/x-java-applet"
                width="5000" height="50"
                archive="sTest11.jar" name="TEST3" id="TEST3">
    <param name="TEST3" value="TEST3" />
    alt : <a href="TEST3.class">TEST3.class</a>
    <!-- Safari needs this -->
    <param name="JAVA_CODEBASE" value="lib" />
    <param name="BGCOLOR" value="000000" />
    <param name="TEXTCOLOR" value="FF0000" />
    <param name="TEXT" value="Test" />
    <param name="SPEED" value="250" />
    <param name="RANDOMCOLOR" value="1" />
    <param name="mayscript" value="yes"/>
    <param name="scriptable" value="true" />
</object>

So when the web page is opened, the applet starts. I have a javascript file which calls the init() method to call a first web service. Then I retrieve datas, that I need to call a second web service. That's why I need here to add parameters to my java applet. If I use in javascript:

document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';

and then

javascript:document.getElementById('TEST3').mymethod2();

it does not work. The applet is not reloaded. (but it works if I put manually a parameter before loading the whole page, so the problem is the reloading of the applet in order to take the new parameter). I tried to call the stop() method, then the destroy() one, then another init() and then the request I want but it does not work.

I manage to do my requests with different applets (with several innerHTML which create each one applet step by step), but it does not work exactly as I want, and I really would prefer use only one.

If you have any idea, thank you very much for your help.

Try invoking your function like this instead:

document.TEST3.mymethod2();

And see if that works.

EDIT

Based off your comments I understand you were trying to pass additional startup parameters to the Applet on your page. Which is of course not really possible (keyword startup :). With your first method you had this:

document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';

But your object tag (correctly) doesnt have any innerHTML . And params are not specified in the object tag body anyway so no matter what this will have no useful effect. Your second method had this:

javascript:document.getElementById('TEST3').mymethod2();

Which according to your comments works, but of course there is no data getting passed in so your Applet parameters do not change. What you do want to do is this:

javascript:document.getElementById('TEST3').mymethod2(someparameter);

Of course, your method signature on the Applet should match!

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