This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

url

Summary

The absolute URL as resolved by the constructor.

Property of apis/websocket/WebSocketapis/websocket/WebSocket

Syntax

Note: This property is read-only.

var result = element.url;

Return Value

Returns an object of type StringString

The URL specifies the following details about the connection.

  • Scheme ― The scheme must be “ws” or "wss". The “ws” scheme is insecure, while “wss” indicates a secure connection. Pages that are served over HTTP should use “ws” WebSockets, while HTTPS pages should use "wss". Attempting to use a scheme other than “ws” or “wss” throws an error.
  • Host ― The host is the name or IP address of the server.
  • Port ― This specifies the remote port to connect to. If the port is not specified then a default is selected based on the scheme. “ws” connections default to port 80, while “wss” connections default to 443.
  • Resource Name ― The resource name is the path component of the URL which follows the host/port. This includes the URL query component (the part following a question mark), if one is present. The resource name can be omitted, in which case it defaults to a forward slash "/".

Examples

Example URLs

scheme://host:port/resource
ws://localhost:8080/echo
wss://cjihrig.com

Notes

You can use this property to make sure that the URL that is used for the connection is parsed the way the app expects.

Related specifications

W3C WebSocket Specification
W3C Candidate Recommendation

Attributions