11

I'm a bit new to javascript and I'm having a minor problem:

I'm trying to redirect to a page (which then performs a redirect) in javascript. I'm setting the window.location like so:

window.location = "./RedirectPage.aspx?ReturnUrl=page.aspx?key=val&key2=val2";

Now, on RedirectPage.aspx when it's trying to redirect to the page that I passed in as the ReturnUrl, it is parsing key2=val2 as being another querystring parameter for RedirectPage instead of the ReturnUrl.

It makes sense that it does that, but that's not what I am trying to do... any idea how I might solve this?

1
  • Your ampersands have been encoded somewhere. You'll need to examine where the encoding is happening.
    – kinakuta
    Commented Apr 30, 2012 at 15:38

2 Answers 2

21

You want to URL encode the ReturnUrl querystring.

window.location = "./RedirectPage.aspx?ReturnUrl="+encodeURIComponent("page.aspx?key=val&key2=val2");
0
3

Try this:

window.location = "./RedirectPage.aspx?"+encodeURIComponent("ReturnUrl=page.aspx?key=val&key2=val2")

You need to escape the ampersand (for use in a query string).

1
  • 1
    So close. As it turned out, ReturnUrl= needed to be outside of the encodeURIComponent. +1 to both you and Theron, but his was more correct. Thank you. Commented Apr 30, 2012 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.