2

My main question is in bold at the bottom. I would love an answer to that especially but if you'd like to help me figure out the rest of the problem, please continue reading.

I am working on a web application whose session expiration is being handled by a Spring backend (it's the default Tomcat 30-minute session expiration). If you are logged into the application and then you type in 'www.myapplication.com/portal/logout' (not the real url, obv.) you are logged out and redirected to the login page. Great. However, if you set

window.location = 'http://www.myapplication.com/portal/logout' 

in the client-side javascript, that url appears in the url bar in your browser but a whitelabel error page results which is being generated by another service on the backend.

Why is there a difference between typing the url versus setting window.location in the code? Should there be a difference? Or do you think this other service is funking with redirection? If so, why would the same error not occur when you type the url?

PS. I also tried window.location.href = url and window.location.replace(url), to the same effect.

mkhbragg
  • 131
  • 3
  • 12

2 Answers2

2

You should try:

window.location.assign(url);
Buzinas
  • 11,597
  • 2
  • 36
  • 58
0

Setting window.location is a common error. The location object has a function called assign that will open a new location.

Try using the following instead:

window.location.assign('http://www.myapplication.com/portal/logout')

You could also use the open() function of the window object.

window.open('http://www.myapplication.com/portal/logout')

Mike Hamilton
  • 1,519
  • 16
  • 24