J
j.e.frank
I am puzzled by some behavior that I'm seeing and I hope that someone
can enlighten me. It will take me a few moments to explain the
problem, but it does relate to javascript eventually.
I need to include one URL's query string in the contents of a second
URL. So for example, URL 1 might be
http://www.example.com/pageone.html?param1=value1
and then (conceptually) URL 2 would be
http://www.example.com/pagetwo.html?qs=param1=value1
Clearly this is not a legal query string because of the second "=". I
need to encode the query string from URL 1, which is easy enough to do
on the server side, so that the actual rendering of URL 2 becomes
http://www.example.com/pagetwo.html?qs=param1=value1
So far so good. Now I want to put URL 2 as the href of an <a> tag, and
on the server side, when someone clicks on it, be able to extract out
the original query string from URL 1. This works fine if I do
something like this:
<a
href="http://www.example.com/pagetwo.html?qs=param1=value1">click</a>
But I actually need to do some other things besides a simple GET
request, so my href is a javascript call:
<a href="javascript:
doSomething('http://www.example.com/pagetwo.html?qs=param1=value1')">click</a>
Now finally we get to my problem. In this scenario, the URL appears to
be decoded before it ever gets anywhere, much less all the way back to
the server. If the first line of the doSomething() function is to call
alert() on the parameter passed in, it has already turned the %3D back
into an = sign. This does not make sense to me. Naturally, this means
that on the server side I cannot extract out the query string from URL
1 as I would like to.
Interestingly, if I do a similar technique but use the onclick of the
<a> tag instead of the href, the URL comes through as planned (i.e.
still with %3D). So there's something strange about the combination of
javascript and the href attribute. I have tried this in both IE 6 and
FF 1.5.0.6 with the same results, so at least it's consistent, and
there's probably some reason for it that I'm not aware of. (There is a
reason I can't use the onclick, or else I would most likely not be
asking for help.)
Can anyone shed some light on why this happens?
can enlighten me. It will take me a few moments to explain the
problem, but it does relate to javascript eventually.
I need to include one URL's query string in the contents of a second
URL. So for example, URL 1 might be
http://www.example.com/pageone.html?param1=value1
and then (conceptually) URL 2 would be
http://www.example.com/pagetwo.html?qs=param1=value1
Clearly this is not a legal query string because of the second "=". I
need to encode the query string from URL 1, which is easy enough to do
on the server side, so that the actual rendering of URL 2 becomes
http://www.example.com/pagetwo.html?qs=param1=value1
So far so good. Now I want to put URL 2 as the href of an <a> tag, and
on the server side, when someone clicks on it, be able to extract out
the original query string from URL 1. This works fine if I do
something like this:
<a
href="http://www.example.com/pagetwo.html?qs=param1=value1">click</a>
But I actually need to do some other things besides a simple GET
request, so my href is a javascript call:
<a href="javascript:
doSomething('http://www.example.com/pagetwo.html?qs=param1=value1')">click</a>
Now finally we get to my problem. In this scenario, the URL appears to
be decoded before it ever gets anywhere, much less all the way back to
the server. If the first line of the doSomething() function is to call
alert() on the parameter passed in, it has already turned the %3D back
into an = sign. This does not make sense to me. Naturally, this means
that on the server side I cannot extract out the query string from URL
1 as I would like to.
Interestingly, if I do a similar technique but use the onclick of the
<a> tag instead of the href, the URL comes through as planned (i.e.
still with %3D). So there's something strange about the combination of
javascript and the href attribute. I have tried this in both IE 6 and
FF 1.5.0.6 with the same results, so at least it's consistent, and
there's probably some reason for it that I'm not aware of. (There is a
reason I can't use the onclick, or else I would most likely not be
asking for help.)
Can anyone shed some light on why this happens?