I want to construct a WebSocket URI relative to the page URI at the browser side. Say, in my case convert HTTP URIs like
http://example.com:8000/path https:/
easy:
location.href.replace(/^http/, 'ws') + '/to/ws' // or if you hate regexp: location.href.replace('http://', 'ws://').replace('https://', 'wss://') + '/to/ws'