Hi,
Is there an equivalent to URLdecode() in javascript ?
Details:
In Asp.Net I am using
HttpContext.Current.Response.Redirect("genericerro r.htm?ErrStr=" &
Err.Number & ": " & Err.Description)
In genericerror.htm I have:
<SCRIPT LANGUAGE="javascript">
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 13 17556
I beleive you want encodeURI and decodeURI (or maybe encodeURIComponent and
decodeURIComponent)
"Jim Andersen" <ji*@officeconsult.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.Current.Response.Redirect("genericerro r.htm?ErrStr=" & Err.Number & ": " & Err.Description)
In genericerror.htm I have:
<SCRIPT LANGUAGE="javascript"> 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
kaeli wrote: In article <bh**********@sunsite.dk>, ji*@officeconsult.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 RegisterClientScriptBlock as a kind of msgbox.
msgStr="Hello"
pageref.RegisterClientScriptBlock("aaa", "<script language=JavaScript>
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
In article <bi**********@sunsite.dk>, ji*@officeconsult.dk enlightened
us with... In .NET I use RegisterClientScriptBlock as a kind of msgbox. msgStr="Hello" pageref.RegisterClientScriptBlock("aaa", "<script language=JavaScript> 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 overcomplicating 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
-------------------------------------------------
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 overcomplicating 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
In article <bi**********@sunsite.dk>, ji*@officeconsult.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 overcomplicating 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
-------------------------------------------------
kaeli wrote: In article <bi**********@sunsite.dk>, ji*@officeconsult.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 overcomplicating 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.Number & ": " & err.Description
and once .Description was
no such object 'zzzTblTst'
I am gonna experiment with server.getlasterror etc, and that could (AFAIK)
include both [ and & and { etc.
/jim
>> 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
On Thu, 4 Sep 2003 16:54:20 +0200, "Jim Andersen"
<ji*@officeconsult.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.
decodeURIComponent
Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jim Ley wrote: On Thu, 4 Sep 2003 16:54:20 +0200, "Jim Andersen" <ji*@officeconsult.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.
decodeURIComponent
Jim.
So why isn't this working:
foo.aspx:
Response.Redirect("tst.htm?msg=" & HttpUtility.UrlEncode("6: division by
zero"))
tst.htm
<body>
Msg=
<SCRIPT LANGUAGE="javascript">
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+by+zero
I change tst.htm:
var=FunctionToGetQuerystring;
document.write(decodeURIComponent(var))
Result: I get Msg= 6:+division+by+zero
If I change foo.aspx:
Response.Redirect("tst.aspx?msg=" & HttpUtility.UrlEncode("6: division by
zero"))
and have tst.aspx do:
Response.Write("msg=" & HttpUtility.UrlDecode(Request.QueryString("msg")))
I finally get the desired result
msg=6: division by zero
regards
Jim Andersen
On Fri, 5 Sep 2003 12:10:18 +0200, "Jim Andersen"
<ji*@officeconsult.dk> wrote: foo.aspx: Response.Redirect("tst.htm?msg=" & HttpUtility.UrlEncode("6: division by zero")) Result: I get Msg= 6:+division+by+zero
It looks like your HttpUtility.UrlEncode is not performing correct URI
encoding, it appears to be encoding space as +, this is not correct,
your problem is with that, not with javascript.
Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/ ji*@jibbering.com (Jim Ley) writes: It looks like your HttpUtility.UrlEncode is not performing correct URI encoding, it appears to be encoding space as +, this is not correct,
Well, for some definition of correct, it is. It is the same way form
data are encoded for the GET transfer method.
The solution is to change all plusses to spaces before decoding with
unescape:
var decoded = unescape(encoded.replace(/\+/g," "));
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
On 05 Sep 2003 12:48:38 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote: ji*@jibbering.com (Jim Ley) writes:
It looks like your HttpUtility.UrlEncode is not performing correct URI encoding, it appears to be encoding space as +, this is not correct,
Well, for some definition of correct, it is. It is the same way form data are encoded for the GET transfer method.
True, but it is not URIEncoding which the method name suggests.
Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/
Lasse Reichstein Nielsen wrote: The solution is to change all plusses to spaces before decoding with unescape:
var decoded = unescape(encoded.replace(/\+/g," "));
Thx Lasse for the helpful answer (as opposed to Jim Ley's fantasies).
/jim This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
by: John Grandy |
last post by:
Does Server.URLDecode() need to be applied to Request.QueryString(<key
name>) ?
|
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...
|
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...
|
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;...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |