1

Is it possible to change change subdomain without refreshing the page? E.g. from www.somedomain.com to aaa.somedomain.com without full reload?

Edit: I need to switch subdomain part only so in above example somedomain.com stays same, only www is changed to aaa

spirytus
  • 10,726
  • 14
  • 61
  • 75
  • 1
    What are you actually trying to achieve here? Is this the XY problem? https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem If you're switching domain you will need to reload – TommyBs Dec 02 '19 at 21:23
  • 4
    No, there is no way to do that. The HTML5 History API can help with folders, but not domains (since the subdomain is considered a different origin, security-wise). – Heretic Monkey Dec 02 '19 at 21:27
  • 1
    ANd after the edit, answer is still no. You need to redirect. – epascarello Dec 02 '19 at 21:30

1 Answers1

4

what you are looking for is History.pushState(), but as described here,

It can't be done. This is by design. There are no exceptions.

From the Mozilla pushState documentation:

The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception.

Pezhvak
  • 9,633
  • 7
  • 29
  • 39