翻译正在进行中。

WebSocket.onopen属性定义一个事件处理程序,当WebSocket 的连接状态readyState 变为“OPEN”时调用;这意味着当前连接已经准备好发送和接受数据。这个事件处理程序通过 事件(建立连接时)触发。

 

语法

 

aWebSocket.onopen = function(event) {
  console.log("WebSocket is open now.");
};

返回值

An EventListener.

规范

Specification Status Comment
HTML Living Standard
WebSocket: onopen
Living Standard Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onopenChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari ? WebView Android ? Chrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

文档标签和贡献者

此页面的贡献者: TeabugCC, mdnwebdocs-bot, suciy
最后编辑者: TeabugCC,