Good day.

Is it possible to get the contents of the image (in the form of base64 or dataURL), somehow ignoring the cross-origin polycy in the browser?

So, for example, code ( sandbox here ):

function dataURL (src, callback) { var img = new Image; img.onload = function () { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; canvas.getContext("2d").drawImage(img, 0, 0); try { callback(canvas.toDataURL()); } catch (e) { alert(e); } }; img.src = src; } // Используем dataURL( "http://a.disquscdn.com/uploads/users/10355/3829/avatar92.jpg?1413802608", function (data) { alert(data); } ); 

It does not work, but gives an error: The operation is insecure. code: "18" The operation is insecure. code: "18"

  • one
    No, only enabled CORS will solve this problem. - RubaXa
  • Just like the proxy with CORS solves the problem. :-) - chernomyrdin
  • So why ask if you know the answer? CORS to get around in any way, then he CORS. - RubaXa
  • Perhaps I do not know everything. :-( It is possible that I missed something from the latest innovations in HTML5, before it was difficult with file-upload, and now createObjectURL / FormData and so on - chernomyrdin

0