• Skip to main content
  • Skip to search
    • Technologies Overview
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs
    • Browser Extensions
    • MathML
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
    • Send Feedback
    • Contribute to MDN
    • Report a content issue 🌐
    • Report a platform issue 🌐
  1. Web 开发技术
  2. Web API 接口参考
  3. WebSocket
  4. WebSocket.onmessage
  • Change language
  • View in English

Table of contents

  • 语法
  • 值
  • 规范
  • 浏览器兼容性

WebSocket.onmessage

WebSocket.onmessage 属性是一个当收到来自服务器的消息时被调用的 EventHandler (en-US)。它由一个MessageEvent调用。

语法

aWebSocket.onmessage = function(event) {
  console.debug("WebSocket message received:", event);
};

值

一个 EventListener.

规范

规范 状态 注释
HTML Living Standard
WebSocket: onmessage
Living Standard 初始定义

浏览器兼容性

BCD tables only load in the browser

Found a problem with this page?

  • Source on GitHub
  • Report a problem with this content on GitHub
  • Want to fix the problem yourself? See our Contribution guide.

Last modified: Apr 21, 2021, by MDN contributors

Change your language

Related Topics

  1. WebSocket
  2. Constructor
    1. WebSocket()
  3. 属性
    1. binaryType
    2. bufferedAmount
    3. extensions
    4. onclose
    5. onerror
    6. onmessage
    7. onopen
    8. protocol
    9. readyState
    10. url
  4. 方法
    1. close()
    2. send()
  5. Events
    1. close
    2. error
    3. message
    4. open
  6. 继承
    1. EventTarget
  • Web Technologies
  • Learn Web Development
  • About MDN
  • Feedback
  • About
  • MDN Web Docs Store
  • Contact Us
  • Firefox

MDN

Mozilla

© 2005-2021 Mozilla and individual contributors. Content is available under these licenses.

  • Terms
  • Privacy
  • Cookies