Page 1 of 1

Modifying applet parameters in Client-side Javascript

Posted: Wed May 12, 2004 7:20 pm
by Schol-R-LEA
I've had a rather frustrating problem today, which I was hoping to get some insight on. I have been working on a contract which involves a Java applet, some canned Shockwave, and a Javascript clock. Anyway, part of the goal is to have the applet randomly play a streaming image from a list; while the final version is going to be server-side (probably Javascript ASP, but this hasn't been settled yet), the current demo is being written entirely client-side, from a hardcoded list of examples. The examples are just the ID codes for the images, which are actually stored on a shared server. The IDs are passed to the applet as <PARAM>s. The code examples given for the applet use the deprecated <APPLET> tag, and since when I tried re-writing it with <OBJECT> it would not work under MSIE 6 (though it would under Mozilla 1.6 and Opera 7.3), I left it as it was.

My intention, when I went to code the demo around noon (PDT) today, was to simply write a function to select an ID, and then once I was sure I was getting them selected with reasonable pseudo-randomness (shown using a test page I set up), I then wrote a snippet of Javascript to generate a <PARAM> tag with the appropriate ID value. It went something like this:

Code: Select all

<applet name="foo" code="foo.class">
  <param name="bar" value="whatever">
  <!-- ... more params -->
  <script language="Javascript1.2">
    document.write('<param name="quux" value="' + GetId() + '" />');
  </script>
  <!-- still more params -->
</applet>
However, this didn't work, and unfortunately, it didn't raise a Javascript console error, either; the applet would try to load, then crash.

When that didn't work, I pored over my Javascript and DHTML refs, and tried doing a few web searches, but came up empty. I spend the whole afternoon trying to find some way to set the parameter programatically, but everything I tried either failed the same way, or else turned out to be specific to the applet that a given web page was describing and thus not applicable. Eventually, out of frustration, I tried modifying the applet reference to use an <OBJECT> tag - and to my amazement, it worked (in Mozilla and Opera, anyway). However, since the primary target is IE, this may not be so useful; IE doesn't seem to recognize the tag at all, at least not with the applet in question.

Any suggestions? I'm at wits' end over this. Fortunately, the client is patient, but he will need this working before the 25th.

As a side note, I'm finally seeing some real activity with the freelance work, and I may soon have a long-term contract for some helldesk work - not my first choice of jobs, but since it's done on a telecommuting basis, and the hours are flexible, I am more than willing to do it, esp. after such a long period of unemployment. It also means that I can continue to work on the independent contracting, which is definitely a Good Thing in my not-so-humble opinion.

BTW, why does the forum software keep separating the name of the language into 'Java Script'? I mean, it even does it in the code blocks, which is potentially problematic.

Re:Modifying applet parameters in Client-side Javascript

Posted: Wed May 12, 2004 11:06 pm
by Candy
Schol-R-LEA wrote: The examples are just the ID codes for the images, which are actually stored on a shared server. The IDs are passed to the applet as <PARAM>s. The code examples given for the applet use the deprecated <APPLET> tag, and since when I tried re-writing it with <OBJECT> it would not work under MSIE 6 (though it would under Mozilla 1.6 and Opera 7.3), I left it as it was.
..
Eventually, out of frustration, I tried modifying the applet reference to use an <OBJECT> tag - and to my amazement, it worked (in Mozilla and Opera, anyway). However, since the primary target is IE, this may not be so useful; IE doesn't seem to recognize the tag at all, at least not with the applet in question.
That's just typical ;). Might I suggest considering that IE doesn't like dynamically generated external links that have to be used in-page (IE: loading after completion)?
My intention, when I went to code the demo around noon (PDT) today, was to simply write a function to select an ID, and then once I was sure I was getting them selected with reasonable pseudo-randomness (shown using a test page I set up), I then wrote a snippet of Javascript to generate a <PARAM> tag with the appropriate ID value. It went something like this:

When that didn't work, I pored over my Javascript and DHTML refs, and tried doing a few web searches, but came up empty. I spend the whole afternoon trying to find some way to set the parameter programatically, but everything I tried either failed the same way, or else turned out to be specific to the applet that a given web page was describing and thus not applicable.

Any suggestions? I'm at wits' end over this. Fortunately, the client is patient, but he will need this working before the 25th.
In a limited amount of cases, you could consider making a limited number of web pages with all the ID's (or use a CGI or something) and then include the appropriate one with an iframe or SSI. Would move the problem to the server side, but as you indicated, it's where it has to be in the first place.

You could consider patching up IE :)
BTW, why does the forum software keep separating the name of the language into 'Java Script'? I mean, it even does it in the code blocks, which is potentially problematic.
That's a sure bug, I think it does it so you don't insert javascript code when html has been turned on, so you don't hack the forum or redirect users :). Still, considering the type of forum this is, I'd turn HTML off and that "feature" too.

Re:Modifying applet parameters in Client-side Javascript

Posted: Wed May 12, 2004 11:55 pm
by dzth
- cant GetId() be written in java ?

- if an applet can load an arbitrary page,
then perhaps parameters could be read that way
(or an applet loading another applet - php spicing things up)

- a demo should resemble the final scheme

- http://www.w3.org/Amaya/ (nasty ..)

Re:Modifying applet parameters in Client-side Javascript

Posted: Thu May 13, 2004 7:18 am
by Eero Ränik
Use server-side pages, when you're doing it client-side there's always a chance that something could get messed up.
And besides, you don't need to specify the language when you're adding a script (at least in IE).

Re:Modifying applet parameters in Client-side Javascript

Posted: Thu May 13, 2004 8:17 am
by Candy
Eero R?nik wrote: And besides, you don't need to specify the language when you're adding a script (at least in IE).
Consider reading the html specification.

Re:Modifying applet parameters in Client-side Javascript

Posted: Thu May 13, 2004 10:03 am
by Eero Ränik
I just wanted to say that there's no point in separating Java and Script when any script will run in Internet Explorer without specifying the language anyway. I know what the specs say.

Re:Modifying applet parameters in Client-side Javascript

Posted: Thu May 13, 2004 11:44 am
by Candy
Eero R?nik wrote: ...that there's no point in ...

I know what the specs say.
and you strongly imply they are useless and should therefore not be followed. That's not the way to handle a spec.

Re:Modifying applet parameters in Client-side Javascript

Posted: Thu May 13, 2004 12:10 pm
by Eero Ränik
I didn't mean it's pointless to specify the language, I meant it's pointless to separate Java and Script... :P