Provide fallbacks for html parsing

This commit is contained in:
Niklas von Hertzen 2014-09-28 00:11:54 +03:00
parent 8a3d1d7f22
commit bd1abe1857
3 changed files with 34 additions and 6 deletions

18
dist/html2canvas.js vendored
View File

@ -722,8 +722,22 @@ function loadUrlDocument(src, proxy, document, width, height, options) {
function documentFromHTML(src) {
return function(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
var parser = new DOMParser(), doc;
try {
doc = parser.parseFromString(html, "text/html");
} catch(e) {
log("DOMParser not supported, falling back to createHTMLDocument");
doc = document.implementation.createHTMLDocument("");
try {
doc.open();
doc.write(html);
doc.close();
} catch(ee) {
log("createHTMLDocument write not supported, falling back to document.body.innerHTML");
doc.body.innerHTML = html; // ie9 doesnt support writing to documentElement
}
}
var b = doc.querySelector("base");
if (!b || !b.href.host) {
var base = doc.createElement("base");

File diff suppressed because one or more lines are too long

View File

@ -154,8 +154,22 @@ function loadUrlDocument(src, proxy, document, width, height, options) {
function documentFromHTML(src) {
return function(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
var parser = new DOMParser(), doc;
try {
doc = parser.parseFromString(html, "text/html");
} catch(e) {
log("DOMParser not supported, falling back to createHTMLDocument");
doc = document.implementation.createHTMLDocument("");
try {
doc.open();
doc.write(html);
doc.close();
} catch(ee) {
log("createHTMLDocument write not supported, falling back to document.body.innerHTML");
doc.body.innerHTML = html; // ie9 doesnt support writing to documentElement
}
}
var b = doc.querySelector("base");
if (!b || !b.href.host) {
var base = doc.createElement("base");