HTML and CSS Reference
In-Depth Information
The method works similar to the OnMessage method. The only difference is that it
takes a byte array (data) instead of string as a parameter. An array of bytes is the
most native and efficient image representation.
When the rest of the clients receive the image, a new <img> element will be created.
You have already seen the way, so you update the onmessage function accordingly:
socket.onmessage = function(event) {
if (typeof === "string") {
// Decode JSON, then display nickname and
// …
else if ( instanceof Blob) {
// Get the raw data and create an image
var blob =;
window.URL = window.URL || window.webkitURL;
var source =
var image = document.createElement("img");
image.src = source;
image.alt = "Image generated from blob";
Search WWH ::

Custom Search