Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  181] [ 7]  / answers: 1 / hits: 85740  / 16 Years ago, fri, february 27, 2009, 12:00:00

I have a javascript function which passes as a query string value another query string.

In other words, I want the query string to be:

However, if I redirect like this:

var url = '';
url += escape('?key=value1&key2=value2');
window.location = url;

it ends up as in firefox and IE7 which means that I can't parse the query string correctly.

I also tried using encodeURIComponent which didn't work either.

Is there another function or a hack to force the redirect to keep the somequery value escaped??

More From » encoding


encodeURIComponent will work. (You may or may not want the leading ‘?’, depending on what the script is expecting.)

var c= 'd e'
var query= '?a=b&c='+encodeURIComponent(c);
var uri= ''+encodeURIComponent(query);
window.location= uri;

Takes me to:

When you hover over that it may appear once-decoded in the browser's status bar, but you will end up in the right place.

escape/unescape() is the wrong thing for encoding query parameters, it gets Unicode characters and pluses wrong. There is almost never a case where escape() is what you really need.

[#99911] Monday, February 23, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 245
Total Questions: 92
Total Answers: 100

Location: Ukraine
Member since Sun, Dec 13, 2020
4 Years ago
jackeline questions