WebSockets

實驗性質: 這是一個實驗中的功能
此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。

WebSocket 是一種讓瀏覽器與伺服器進行一段互動通訊的技術。這個 API 在不必輪詢(poll)伺服器下,讓使用者傳送訊息至伺服器並接受事件驅動回應。

文件

製作 WebSocket 客戶端應用程式
指導如何製作在瀏覽器上跑 WebSocket 客戶端的教程。
WebSockets 參考手冊
客戶端的 WebSocket API 參考手冊。
The WebSocket protocol
WebSocket 協定參考。
Writing WebSocket servers
處理 WebSocket 協定的伺服器端代碼書寫指引。

工具

AJAXJavaScript

瀏覽器相容性

api.WebSocket

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
WebSocket
WebSocket() constructor
url parameter allows https, http, and relative URLs
binaryType
bufferedAmount
close
close event
error event
extensions
message event
open event
protocol
Supports protocol as specified by RFC 6455
readyState
send
url
Available in workers

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

api.WebSocketStream

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
WebSocketStream
Experimental
WebSocketStream() constructor
Experimental
close
Experimental
closed
Experimental
opened
Experimental
url
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

參見