Ampersand in querystring parameter

I am a little new to javascript and I have a little problem:

I am trying to redirect to a page (which then redirects) in javascript. I install window.locationas follows:

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

Now that RedirectPage.aspx tries to redirect to the page that I passed as ReturnUrl, it parses key2 = val2 as another querystring parameter for RedirectPage instead of ReturnUrl.

It makes sense that it is, but that is not what I am trying to do ... any idea how I can solve this?

+5
source share
2 answers

You want the URL to encode the returnUrl query string.

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

Try the following:

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

( ).

+2

All Articles