mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix image loading for cross-origin resources
This commit is contained in:
parent
9af96d3812
commit
82e5a8a7c0
File diff suppressed because one or more lines are too long
4
build/html2canvas.min.js
vendored
4
build/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
@ -39,7 +39,7 @@ ImageLoader.prototype.loadImage = function(imageData) {
|
||||
} else if (this.support.cors && !this.options.allowTaint && this.options.useCORS) {
|
||||
return new ImageContainer(src, true);
|
||||
} else if (this.options.proxy) {
|
||||
return new ProxyImageContainer(src);
|
||||
return new ProxyImageContainer(src, this.options.proxy);
|
||||
} else {
|
||||
return new DummyImageContainer(src);
|
||||
}
|
||||
|
33
src/proxyimagecontainer.js
Normal file
33
src/proxyimagecontainer.js
Normal file
@ -0,0 +1,33 @@
|
||||
function ProxyImageContainer(src, proxy) {
|
||||
var callbackName = "html2canvas_" + proxyImageCount++;
|
||||
var script = document.createElement("script");
|
||||
var link = document.createElement("a");
|
||||
link.href = src;
|
||||
src = link.href;
|
||||
var requestUrl = proxy + ((proxy.indexOf("?") > -1) ? "&" : "?" ) + 'url=' + encodeURIComponent(src) + '&callback=' + callbackName;
|
||||
this.src = src;
|
||||
this.image = new Image();
|
||||
var image = this.image;
|
||||
this.promise = new Promise(function(resolve, reject) {
|
||||
image.onload = resolve;
|
||||
image.onerror = reject;
|
||||
|
||||
window[callbackName] = function(a){
|
||||
if (a.substring(0,6) === "error:"){
|
||||
reject();
|
||||
} else {
|
||||
image.src = a;
|
||||
}
|
||||
window[callbackName] = undefined; // to work with IE<9 // NOTE: that the undefined callback property-name still exists on the window object (for IE<9)
|
||||
try {
|
||||
delete window[callbackName]; // for all browser that support this
|
||||
} catch(ex) {}
|
||||
script.parentNode.removeChild(script);
|
||||
};
|
||||
script.setAttribute("type", "text/javascript");
|
||||
script.setAttribute("src", requestUrl);
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
}
|
||||
|
||||
var proxyImageCount = 0;
|
@ -11,7 +11,7 @@ var h2cSelector, h2cOptions;
|
||||
|
||||
document.write(srcStart + '/tests/assets/jquery-1.6.2.js' + scrEnd);
|
||||
document.write(srcStart + '/tests/assets/jquery.plugin.html2canvas.js' + scrEnd);
|
||||
var html2canvas = ['log', 'nodecontainer', 'stackingcontext', 'textcontainer', 'support', 'imagecontainer', 'gradientcontainer', 'lineargradientcontainer', 'webkitgradientcontainer',
|
||||
var html2canvas = ['log', 'nodecontainer', 'stackingcontext', 'textcontainer', 'support', 'imagecontainer', 'proxyimagecontainer', 'gradientcontainer', 'lineargradientcontainer', 'webkitgradientcontainer',
|
||||
'imageloader', 'nodeparser', 'font', 'fontmetrics', 'core', 'renderer', 'promise', 'renderers/canvas'], i;
|
||||
for (i = 0; i < html2canvas.length; ++i) {
|
||||
document.write(srcStart + '/src/' + html2canvas[i] + '.js?' + Math.random() + scrEnd);
|
||||
@ -30,7 +30,7 @@ var h2cSelector, h2cOptions;
|
||||
logging: true,
|
||||
profile: true,
|
||||
proxy: "http://html2canvas.appspot.com/query",
|
||||
useCORS: true
|
||||
useCORS: false
|
||||
}, h2cOptions));
|
||||
}, 100);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user