最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to prevent window.location.pathname from escaping characters in URL - Stack Overflow

programmeradmin1浏览0评论

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/

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/

Share Improve this question edited Jun 28, 2011 at 3:33 Nick Johnson 101k17 gold badges130 silver badges198 bronze badges asked Jun 28, 2011 at 2:02 morpheusmorpheus 20.4k29 gold badges108 silver badges185 bronze badges 2
  • This doesn't have anything to do with App Engine. – Nick Johnson Commented Jun 28, 2011 at 3:33
  • Ran into the very same problem. Sadly, my only way out was to add a replace('%3F','?') at the end... I my case the suggested 'use location directly' is not applicable since I am manipulating href attribute of buttons that will fetch ajax content. – nicolallias Commented Sep 19, 2018 at 17:00
Add a comment  | 

3 Answers 3

Reset to default 12

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

You can use the following code in javascript to decode URI components:

decodeURIComponent(window.location.pathname) 
发布评论

评论列表(0)

  1. 暂无评论