在查询字符串参数中有一个&符号

Ste*_*ers 6 javascript redirect

我对javascript有点新鲜,我遇到了一个小问题:

我正在尝试重定向到javascript中的页面(然后执行重定向).我window.location这样设定:

window.location = "./RedirectPage.aspx?ReturnUrl=page.aspx?key=val&key2=val2";
Run Code Online (Sandbox Code Playgroud)

现在,在RedirectPage.aspx上,当它试图重定向到我作为ReturnUrl传入的页面时,它正在解析key2 = val2作为RedirectPage的另一个查询字符串参数而不是ReturnUrl.

这样做是有意义的,但这不是我想要做的......任何想法我怎么解决这个问题?

The*_*uhn 18

您想对ReturnUrl查询字符串进行URL编码.

window.location = "./RedirectPage.aspx?ReturnUrl="+encodeURIComponent("page.aspx?key=val&key2=val2");
Run Code Online (Sandbox Code Playgroud)