Commit 93846186 by Omar Khan

Fix cross-domain images and images with relative urls or without explicit protocol

parent a4e1e429
...@@ -8,6 +8,18 @@ function PBDashboardBlock(runtime, element, initData) { ...@@ -8,6 +8,18 @@ function PBDashboardBlock(runtime, element, initData) {
var generateDataUriFromImageURL = function(imgURL) { var generateDataUriFromImageURL = function(imgURL) {
// Given the URL to an image, IF the image has already been cached by the browser, // Given the URL to an image, IF the image has already been cached by the browser,
// returns a data: URI with the contents of the image (image will be converted to PNG) // returns a data: URI with the contents of the image (image will be converted to PNG)
// Expand relative urls and urls without an explicit protocol into absolute urls
var a = document.createElement('a');
a.href = imgURL;
imgURL = a.href;
// If the image is from another domain, just return its URL. We can't
// create a data URL from cross-domain images:
// https://html.spec.whatwg.org/multipage/scripting.html#dom-canvas-todataurl
if (a.origin !== window.location.origin)
return imgURL;
var img = new Image(); var img = new Image();
img.src = imgURL; img.src = imgURL;
if (!img.complete) if (!img.complete)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment