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.

1
  • @Buzinas window.location.assign(url) was the way to go. Thanks! The rerouting works now.
    – mkhbragg
    Commented Sep 26, 2015 at 0:46

2 Answers 2

2

You should try:

window.location.assign(url);
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')

2
  • The object window.location doesn't have a method named open.
    – Buzinas
    Commented Sep 25, 2015 at 21:42
  • @Buzinas you're right, open is a method of window. assign() is what I was thinking of Commented Sep 26, 2015 at 11:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.