We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › retrieve parameter from url
Page Index Toggle Pages: 1
retrieve parameter from url ? (Read 4970 times)
retrieve parameter from url ?
Jun 15th, 2005, 11:08am
 
I'm looking for a simple way to pass a ( one, 1) parameter from the url to the index.html to the param value for the applet.

The second part of this works fine as described here http://www.processing.org/reference/param_.html .

The parameter (below: "51") needs to be hardcoded into the index.tml file as follows:
// <applet code="param_" archive="param_.jar" width=100 height=100>
// <param name="back" VALUE="51">  
// </applet>

What I want is to read the parameter from the url. Using javascript, this works fine as follows:
is this is the url: http://fileorserverpath/mysketch/applet/index.html#51
then this script will give me the "51" :

<script type="text/javascript">
url_param = decodeURI(window.location.hash.substr(1));
</script>

which can be tested by e.g. entering
alert(url_param);
before </script>.

However, and that's my question:
I was not able to pass this parameter (url_param) which has the content "51" to the VALUE needed for the applet.

I searched through the processing alpha and beta boards, went to sun and netscape documentation, but I assume that I am just not expert enough when it comes to advanced code writing.

I would prefer not to change anything in the processing code, but to handle everything in the index.html file.

Any recommenations? And: simple, please, I am not a expert code writer ( think I mentioned that before, and which is why I like processing.org)

Thanks.
Re: retrieve parameter from url ?
Reply #1 - Jun 15th, 2005, 3:54pm
 
with javascript you can't change the values of params and have them update in a java applet (if i understand your question correctly), so param() is only valid once, for the time when the page loads. so you'd have to reload the page (and applet) to get a new value.

to get new data while the applet is running, you might have a second script that just gives you params as a text file, which you could read with loadStrings().
Re: retrieve parameter from url ?
Reply #2 - Jun 15th, 2005, 4:40pm
 
To clarify the need:

I don't want to CHANGE them (during runtime), I only want to set them once before the applet is even started. And then it would be fine for me.
So it would be fine if it's only valid once for the time when the page load.
1. Browser calls the http://../index.html#51
2. When the browser interprets the file, if finds the javascript which pulls the "51" from the url.
3. AND THAT's MISSING: this value is then passed to the VALUE which is a parameter for the java applet.
4. The java applett is called, including the parameter, started, and it runs.
5. needs to run only once, fine with me.

So it would be only step 3 above that I need clarification about. Is it REALLY not possible?

Christian
Re: retrieve parameter from url ?
Reply #3 - Jun 15th, 2005, 5:32pm
 
perhaps use document.write() to write out the code for the applet, along with some javascript that grabs the url to get the "51" out of it?
Re: retrieve parameter from url ?
Reply #4 - Jun 15th, 2005, 9:36pm
 
hi christian,

do you know that you can call methods in javascript from the applet? So it would be possible to set variables in the applet directly, instead of using html-param values.

If you got an applet called Processing in the applet-element, you can reference it in javascript like:


html:
Code:

<APPLET CODE="Processing.class" NAME="Processing" WIDTH=150 HEIGHT=25></APPLET>


javascript:
Code:

document.Processing




if you got a variable "value" in your processing-code (maybe you have to declare it public), you can set this in javascript:

Code:
document.Processing.value = 51;


This is just a quick summary of what I found here:

http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/

Look into Chapter 4 if you wanna know more.

Maybe this will help you.

Re: retrieve parameter from url ?
Reply #5 - Jun 16th, 2005, 3:37pm
 
thanks for the tips, I'll try. It's a little bit more complicated than I was hoping (easy would be to reuse the processing param function, see my dream below). The example on the netscape page did not work when I tried it, and processing complains about the words "public" and "void" in that context when I enter part of that code.
Nevertheless, I'll do three things:
- try out what you proposed
- watch this space for more replies
- keep waiting for someone who tells me how to enter my "dream" function, which would be similar to:

<applet code="param_" archive="param_.jar" width=100 height=100>  
<param name="back" VALUE="javascript:decodeURI(window.location.hash.substr(1))">  
</applet>

Don't try this at home: it does not work. But it would be nice.
Page Index Toggle Pages: 1