1

I want to navigate to a URL on my site. This is what I have:

var TheDemoURL = window.location.host;

if (SomeCondition1) { TheDemoURL = TheDemoURL + '/fr/demo'; }
if (SomeCondition2) { TheDemoURL = TheDemoURL + '/de/demo'; }
...

window.location.replace(TheDemoURL);

Initially, in the variable watch, I have TheDemoURL: "localhost:49173" and when I alert the final TheDemoURL is looks a good URL but in reality nothing happens.

Why is this not working?

halfer
  • 19,471
  • 17
  • 87
  • 173
frenchie
  • 48,391
  • 102
  • 295
  • 498

2 Answers2

1

Ok, for those who come here, the solution was to add this:

var TheDemoURL = window.location.protocol + '//' + window.location.host;

Not sure if this is specific to asp.net but it made it work.

frenchie
  • 48,391
  • 102
  • 295
  • 498
  • Glad you were able to figure it out. However, I do still suggest that you use `self` here instead of `window` in order to ensure that things work correctly in case your site is even loaded in an iframe. – Vivian River Jun 09 '14 at 15:05
0

Try using

self.location = TheDemoURL;

This will take into account iframes and other weirdness.

Vivian River
  • 29,986
  • 58
  • 187
  • 303