DISPLAY WEBSOCKET MESSAGES

After you have a WebSocket client that can send messages to a WebSocket service, it makes sense to display the service response messages back to the web browser. Additional information, such as the connection status, error messages, and outgoing messages, is useful to display, too. The best way to do this is to create an output element and use jQuery’s append method to inject information into it. You also can use jQuery’s scrollTop method to ensure that the window is always showing the last entry, which appears at the bottom of the scrollable window.

Because the <output> tag can potentially scroll down the screen, it is a good idea to use the CSS overflow property.

This enables you to limit the height and width and ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.