简体   繁体   中英

How to prevent window.location.pathname from escaping characters in URL

I am developing a google app engine app. I am trying to redirect user to login page when a button is clicked. To do this I set window.location.pathname to following string /_ah/login?continue=http%3A//localhost%3A8080/ . However, chrome escapes the string so that the full URL becomes http://localhost:8080/_ah/login%3Fcontinue=http%3A//localhost%3A8080/ , and this gives a 404 error. How can I prevent this from happening? The URL that works is http://localhost:8080/_ah/login?continue=http%3A//localhost%3A8080/

Set window.location.href instead.

I think you're better off just using window.location.href. In both Chrome and Firefox window.location.href="/?foofoo" redirects to <domain:port>/?foofoo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM