473,561 Members | 3,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URLdecode ?

Hi,

Is there an equivalent to URLdecode() in javascript ?

Details:
In Asp.Net I am using
HttpContext.Cur rent.Response.R edirect("generi cerror.htm?ErrS tr=" &
Err.Number & ": " & Err.Description )

In genericerror.ht m I have:

<SCRIPT LANGUAGE="javas cript">
var url = window.location .href;
var urlPos = url.indexOf('?' ) + 1;
var urlLength = url.length - urlPos;

if (urlPos > 0) {
url.substr(url, urlPos, urlLength);
url.split('&');
var values = url.split('&');
value = values[0].split('=');
document.write( value[1]);
}
</SCRIPT>

But I have problems with whitespace (and perhaps later other "funny" chars)
so how do I make the string "safe" or "back to normal" ?

tia
/jim
Jul 20 '05 #1
13 17566
I beleive you want encodeURI and decodeURI (or maybe encodeURICompon ent and
decodeURICompon ent)

"Jim Andersen" <ji*@officecons ult.dk> wrote in message
news:bh******** **@sunsite.dk.. .
Hi,

Is there an equivalent to URLdecode() in javascript ?

Details:
In Asp.Net I am using
HttpContext.Cur rent.Response.R edirect("generi cerror.htm?ErrS tr=" &
Err.Number & ": " & Err.Description )

In genericerror.ht m I have:

<SCRIPT LANGUAGE="javas cript">
var url = window.location .href;
var urlPos = url.indexOf('?' ) + 1;
var urlLength = url.length - urlPos;

if (urlPos > 0) {
url.substr(url, urlPos, urlLength);
url.split('&');
var values = url.split('&');
value = values[0].split('=');
document.write( value[1]);
}
</SCRIPT>

But I have problems with whitespace (and perhaps later other "funny" chars) so how do I make the string "safe" or "back to normal" ?

tia
/jim

Jul 20 '05 #2
kaeli wrote:
In article <bh**********@s unsite.dk>, ji*@officeconsu lt.dk enlightened
us with...
But I have problems with whitespace (and perhaps later other "funny"
chars) so how do I make the string "safe" or "back to normal" ?


var x = unescape(url);


thx !

Along the same lines...

In .NET I use RegisterClientS criptBlock as a kind of msgbox.
msgStr="Hello"
pageref.Registe rClientScriptBl ock("aaa", "<script language=JavaSc ript>
alert('" & msgstr & "')</SCRIPT>")

works great. BUT, not if msgStr="Hel'lo" (with a single quote). And the
content of msgStr is of course unknown to me at runtime.

Whats the syntax for escaping msgstr ?

tia
/jim

Jul 20 '05 #3
In article <bi**********@s unsite.dk>, ji*@officeconsu lt.dk enlightened
us with...
In .NET I use RegisterClientS criptBlock as a kind of msgbox.
msgStr="Hello"
pageref.Registe rClientScriptBl ock("aaa", "<script language=JavaSc ript>
alert('" & msgstr & "')</SCRIPT>")

works great. BUT, not if msgStr="Hel'lo" (with a single quote). And the
content of msgStr is of course unknown to me at runtime.

Whats the syntax for escaping msgstr ?


Technically? A backslash before any quotes. That's the hard way, though.
Make the single quotes into double quotes and escape them so they don't
mess up your VB string. Then you won't have to worry about single
quotes, but double quotes will still mess you up.
In VB, IIRC, to escape a double quote literal you preface it with
another double quote. In javascript, you use a backslash.

alert(""" & msgstr & """)</SCRIPT>

You could always parse msgstr and put a single backslash before any
quotes, but I think that's overcomplicatin g things if all you need to
worry about are single quotes.
-------------------------------------------------
~kaeli~
Press any key to continue or any other key to quit.
Who is General Failure and why is he reading
my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #4
kaeli wrote:
Whats the syntax for escaping msgstr ?
In javascript, you use a backslash.

alert(""" & msgstr & """)</SCRIPT>

You could always parse msgstr and put a single backslash before any
quotes, but I think that's overcomplicatin g things if all you need to
worry about are single quotes.


yes... but is that all I need to worry about ? What else could freak that
javascript out of working ?

/jim
Jul 20 '05 #5
In article <bi**********@s unsite.dk>, ji*@officeconsu lt.dk enlightened
us with...

alert(""" & msgstr & """)</SCRIPT>

You could always parse msgstr and put a single backslash before any
quotes, but I think that's overcomplicatin g things if all you need to
worry about are single quotes.


yes... but is that all I need to worry about ? What else could freak that
javascript out of working ?


Just having embedded double quotes, AFAIK.

I don't think any other normal characters would be a problem. I assume
since you have control of the string, no really odd characters (like
non-printing chars or foreign chars) would be entered.

-------------------------------------------------
~kaeli~
Press any key to continue or any other key to quit.
Who is General Failure and why is he reading
my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #6
kaeli wrote:
In article <bi**********@s unsite.dk>, ji*@officeconsu lt.dk enlightened
us with...

alert(""" & msgstr & """)</SCRIPT>

You could always parse msgstr and put a single backslash before any
quotes, but I think that's overcomplicatin g things if all you need
to worry about are single quotes.


yes... but is that all I need to worry about ? What else could freak
that javascript out of working ?


Just having embedded double quotes, AFAIK.

I don't think any other normal characters would be a problem. I assume
since you have control of the string, no really odd characters (like
non-printing chars or foreign chars) would be entered.


I actually do
msgstr=err.Numb er & ": " & err.Description
and once .Description was
no such object 'zzzTblTst'
I am gonna experiment with server.getlaste rror etc, and that could (AFAIK)
include both [ and & and { etc.

/jim
Jul 20 '05 #7
>> But I have problems with whitespace (and perhaps later other "funny"
chars)
so how do I make the string "safe" or "back to normal" ?
var x = unescape(url);


hmmm, nope.

Have searched hi&lo on google and it seems it's a known issue. .Net and Java
doesn't use the same algorithm for encoding-decoding. So I don't get my
original string.

/jim
Jul 20 '05 #8
On Thu, 4 Sep 2003 16:54:20 +0200, "Jim Andersen"
<ji*@officecons ult.dk> wrote:
Have searched hi&lo on google and it seems it's a known issue. .Net and Java
doesn't use the same algorithm for encoding-decoding. So I don't get my
original string.


decodeURICompon ent

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9
Jim Ley wrote:
On Thu, 4 Sep 2003 16:54:20 +0200, "Jim Andersen"
<ji*@officecons ult.dk> wrote:
Have searched hi&lo on google and it seems it's a known issue. .Net
and Java doesn't use the same algorithm for encoding-decoding. So I
don't get my original string.


decodeURICompon ent

Jim.


So why isn't this working:

foo.aspx:
Response.Redire ct("tst.htm?msg =" & HttpUtility.Url Encode("6: division by
zero"))

tst.htm
<body>
Msg=
<SCRIPT LANGUAGE="javas cript">
var url = window.location .href;
var urlPos = url.indexOf('?' ) + 1;
var urlLength = url.length - urlPos;
if (urlPos > 0) {
url.substr(url, urlPos, urlLength);
url.split('&');
var values = url.split('&');
value = values[0].split('=');
document.write( value[1]);
}
</SCRIPT>
</body>

Result: I get Msg= 6%3a+division+b y+zero

I change tst.htm:
var=FunctionToG etQuerystring;
document.write( decodeURICompon ent(var))

Result: I get Msg= 6:+division+by+ zero

If I change foo.aspx:
Response.Redire ct("tst.aspx?ms g=" & HttpUtility.Url Encode("6: division by
zero"))

and have tst.aspx do:
Response.Write( "msg=" & HttpUtility.Url Decode(Request. QueryString("ms g")))
I finally get the desired result
msg=6: division by zero

regards
Jim Andersen
Jul 20 '05 #10

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

Similar topics

2
33457
by: Thomas Henz | last post by:
Hi again, can anyone tell me why it says that the object doesnt support this method? rs is a db query resultset. msg is a db field with urlencoded data in it. ------------ if not rs.eof then do while not rs.eof response.write(server.urldecode(rs("msg")))
0
1385
by: Yifan | last post by:
Hi I want to use UrlDecode() in C++. I have a Win32 Visual C++ (.NET) project #using <mscorlib.dll #using <System.dll #using <System.Web.dll using namespace System using namespace System::Web
1
1979
by: João Santa Bárbara | last post by:
hi all is there any replace for the System.Web.HttpUtility.UrlDecode to windows forms ... thks JSB
5
5718
by: Yifan | last post by:
Hi I want to use UrlDecode() in C++. I have a Visual C++ (.NET) Win32 project #using <mscorlib.dll #using <System.dll #using <System.Web.dll using namespace System using namespace System::Web
4
3416
by: John Hoge | last post by:
Hi, I need to UrlDecode a string in a simple console application, but I am having trouble accessing Server.UrlDecode, even though System.Web is included. The application pulls a text out of a referring URL string and (eventually) will run a simple report. Here is an excerpt of my code: using System;
6
11998
by: John Grandy | last post by:
Does Server.URLDecode() need to be applied to Request.QueryString(<key name>) ?
10
5859
by: Alex | last post by:
Hi, I UrlEncode a value that I put in my querystring. This value originally contains the character "è", which is UrlEncoded to "%E8". When I try to read the value from the querystring, I find out that the character now is "%u00c3%u00a8" in the querystring and thus does not urldecode to the original character, which is a problem. My site is...
1
2109
by: fjm67 | last post by:
I see Google edited my email address. Lets try this. captonline at yahoo dot com Can you guys help me out please? I need to implement urldecode into a php script and don't know how. Here is the string I need to include it into. $this->get_category_dropdown($db,"d",$show->CATEGORY,1);
20
3479
by: gert | last post by:
This based on a example i found at http://www.cs.tut.fi/~jkorpela/ forms/cgic.html #include <fcgi_stdio.h> #include <stdlib.h> int urldecode(char *src, char *last, char *dest){ int code; for (; src != last; src++, dest++){ if (*src == '+') *dest = ' ';
3
26253
by: gert | last post by:
Anybody can tell me what i need to import to make urlDecode() work in python2.5 please. import urllib urllib.urlDecode(post) #doesn't exist urllib.urldecode(post) #doesn't exist urldecode(post) #doesn't exist urlDecode(post) #doesn't exist
0
7637
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...
0
7558
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...
0
7851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8072
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...
1
7605
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...
0
7924
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...
0
5177
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...
1
1171
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
884
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.