473,796 Members | 2,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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%3Dvalue 1">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="javascrip t:
doSomething('ht tp://www.example.com/pagetwo.html?qs =param1%3Dvalue 1')">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 2239
ASM
j.*******@gmail .com a écrit :
>
my href is a javascript call:

<a href="javascrip t:
doSomething('ht tp://www.example.com/pagetwo.html?qs =param1%3Dvalue 1')">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('m e%3Dboy')" --result : me%3Dboy
href="javascrip t:see('me%3Dboy ')" --result : me=boy

var strg1 = 'me%3Dboy';
href="javascrip t:see(strg1)" --result : me%3Dboy
href="javascrip t:see('me%'+'3D boy')" --result : me%3Dboy
href="javascrip t:see('me\x253D boy')" --result : me%3Dboy
href="javascrip t:see('me%253Db oy')" --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="javascrip t:
doSomething('ht tp://www.example.com/pagetwo.html?qs =param1%3Dvalue 1')">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('m e%3Dboy')" --result : me%3Dboy
href="javascrip t: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
5581
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. I have specified <xsl:output method="html"/> and encoding="iso-8859-1". When I apply the xsl:value-of and set the disable-output-escaping to "yes", the HTML formatting tags are displayed correctly, but the French accented characters are...
4
10637
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 class .. var en_20031102=new Sermon("11/02",DLEWIS,"The Lord\'s Supper: The Art Of
5
2211
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 anything I'll write should be stuck on a single file. I thought about creating a funny pop-up. <a href="javascript:myFunction();"... that's because, as you will see, the code for the popup is pretty complex. I've insterted myFunction somewhere...
1
5485
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 has already been answered... I have an XML doc that I am transforming via XSLT and JavaScript in the browser. This allows me to return unsorted data to the browser and allow the user to sort it with a mouseclick and not hit the server just...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.