doc.documentElement.innerHTML only works in FireFox
MPIV userscript uses this code which works in FF/Chrome:
function createDoc(text) {
var doc = d.implementation.createHTMLDocument('MPIV');
doc.documentElement.innerHTML = text;
return doc;
}
Thanks that works. :)
Still, I am wondering if there is a way. Currently if this is the only way, it will cause a bit of a pain in some of my scripts as they need some functionality present in the document object.
Pretty easy in xmlHttpRequest, it just lacks support of referer.
Thank you both. I posted my response without seeing his post.
wOxxOm method seems to works.
> You could also try responseType and responseXML on your XHR.
How?
If you can use the native XMLHttpRequest method (i.e., the request meets the same-origin test), you can get a document object back by setting responseType="document". I haven't tested recently, but this old script uses that approach: http://userscripts-mirror.org/scripts/review/132341.html (see function fetchPreview()).
If you can use the native XMLHttpRequest method (i.e., the request meets the same-origin test), you can get a document object back by setting responseType="document". I haven't tested recently, but this old script uses that approach: http://userscripts-mirror.org/scripts/review/132341.html (see function fetchPreview()).
It works, I use that method in another script. I need the GM version because I need to set referer.
function parseHTML(str) {
var doc;
try {
// firefox and chrome 30+,Opera 12 will error
doc = new DOMParser().parseFromString(str, "text/html");
} catch (ex) {}
if (!doc) {
doc = document.implementation.createHTMLDocument("");
doc.querySelector("html").innerHTML = str;
}
return doc;
}
Thanks.

doc.documentElement.innerHTML only works in FireFox
Raised here
I have a bug present in a number of my scripts. I want a way to convert GM_xmlhttpRequest responseText to a document object. Currently I am using the following method:
var dt = document.implementation.createDocumentType("html", "-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd"), doc = document.implementation.createDocument("", "", dt), documentElement = doc.createElement("html"); documentElement.innerHTML = xhr.responseText; doc.appendChild(documentElement);Works fine in FireFox but it seems all the other major browsers do not support it. Any other way I can fix this?
Current script that use it include "OUJS-1", "Citrus GFork", "deviantArt Gallery Pager", "GM_Update" and "Pixiv++".
Thanks in advance