473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 <atag, 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
<atag 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?

Sep 1 '06 #1
2 2198
ASM
j.*******@gmail.com a écrit :
>
my href is a javascript call:

<a href="javascript:
doSomething('http://www.example.com/pagetwo.html?qs=param1%3Dvalue1')">click</a>

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.
function see(strg) { alert(strg); }

onclick="see('me%3Dboy')" --result : me%3Dboy
href="javascript:see('me%3Dboy')" --result : me=boy

var strg1 = 'me%3Dboy';
href="javascript:see(strg1)" --result : me%3Dboy
href="javascript:see('me%'+'3Dboy')" --result : me%3Dboy
href="javascript:see('me\x253Dboy')" --result : me%3Dboy
href="javascript:see('me%253Dboy')" --result : me%3Dboy
This does not make sense to me.
Because browser translates (decode) your parameter '%3D'
as it use to do whith any href

Tou can deceive the browser doing : '%'+'3D or '\x253D' or '%253D'

\x25 hexacode for %
\x25 similar as %25

You can also use a variable.

--
Stephane Moriaux et son [moins] vieux Mac
Sep 1 '06 #2

ASM wrote:
j.*******@gmail.com a écrit :

my href is a javascript call:

<a href="javascript:
doSomething('http://www.example.com/pagetwo.html?qs=param1%3Dvalue1')">click</a>

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.

function see(strg) { alert(strg); }

onclick="see('me%3Dboy')" --result : me%3Dboy
href="javascript:see('me%3Dboy')" --result : me=boy
I think I understand the way things work, based on your examples, so
thank you for that.
This does not make sense to me.

Because browser translates (decode) your parameter '%3D'
as it use to do whith any href
I remain puzzled by this. Only javascript in combination with the href
attribute causes this decoding behavior. If I just use the href
attribute (no javascript) and give it a URL with %3D in it, that URL
comes through to the server side un-decoded. I could understand if the
browser really did decode anything in the href attribute (although not
sure why this would be a good thing), but this is not the case.

Sep 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records....
4
by: sankofa | last post by:
hi, i can't seem to be able to escape my single quote properly... is it even possible in javascript? this is a portion of my code.. var DLEWIS="Pastor Lewis"; .... Sermon is a yser-defined...
5
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore...
1
by: David Henderson | last post by:
I know 'disable-output-escaping' has been discussed in the past, but I can't put my finger on any of the threads to see if my current problem is addressed. Sorry for re-asking the question if it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.