Escaping/encoding in an href with javascript



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%3Dvalue1

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%3Dvalue1";>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%3Dvalue1')">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?

.



Relevant Pages

  • Re: dynamically setting form action - PLEASE HELP
    ... Javascript has nothing to do with any of this, ... about server side. ... The backend catches the ID from the query string, ... email and b)send the requested resource to the end-user. ...
    (comp.lang.javascript)
  • Re: href="javascript:func()" vs href="#" onclick="javascript:func()"
    ... Well to be precise you only use JavaScript in that post to remove the ... removing the hiding would be an easy way if for some reason the OP ... paths contain md5 hashes that are only easily knowable on the server side. ...
    (alt.html)
  • RE: ad server redirects dont work in XP ser pack 2`
    ... > ad server without using javascript. ... For some reason Win XP users can't click ... then stop without going to the redirect. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: element not showing in Request.Form
    ... | Is there any reason why the below function wouldn't ... | allow the server to "Request.Form? ... "Non sequitur" means that there is a conclusion in the ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Re: dynamically setting form action - PLEASE HELP
    ... but somebody at work here was insisting on it being doable in ... about server side. ...  The backend catches the ID from the query string, ... In none of this is there any need for client-side Javascript. ...
    (comp.lang.javascript)