title: How to construct a WebSocket URI relative to the page URI?
body: <p>I want to construct a WebSocket URI relative to the page URI at the browser side. Say, in my case convert HTTP URIs like</p>
  
  <pre><code>http://example.com:8000/path
  https://example.com:8000/path
  </code></pre>
  
  <p>to</p>
  
  <pre><code>ws://example.com:8000/path/to/ws
  wss://example.com:8000/path/to/ws
  </code></pre>
  
  <p>What I'm doing currently is replace the first 4 letters "http" by "ws", and append "/to/ws" to it. Is there any better way for that?</p>