12

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. Commented Apr 30, 2012 at 15:38

2 Answers 2

22

You want to URL encode the ReturnUrl querystring.

window.location = "./RedirectPage.aspx?ReturnUrl="+encodeURIComponent("page.aspx?key=val&key2=val2");
Sign up to request clarification or add additional context in comments.

Comments

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 Comment

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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.