createObjectURL doesnt work if run on Chrome

canvas, html, javascript, websocket

Solution

From MDN:

This method is prefixed in Chrome and Webkit as `window.webkitURL.createObjectURL()`.

You should test if `URL` exists and then use the appropriate object:

(window.URL ? URL : webkitURL).createObjectURL(evt.data);

Problem

Hello everyone, I've tried to retrieve an image from a websocket server (in .NET) I send the image as bytes then I retrieve it on the client side, the code for retrieving on the client side (using canvas and JavaScript): ``` var c=document.GetElementById("myCanvas"); var ctx=c.getContext("2d"); ws.onmessage=function(evt) { var image=new Image(); image.src=URL.createObjectURL(evt.data); ctx.drawImage(image,0,0); } ``` it perfectly displays the picture on firefox, but at Chrome, it just returning undefined and won't load the image through createObjectURL I'm using Chrome 18.0.1025.162 any idea?

Original source

Related problems