I\'m developing a website using the Seam framework and the RichFaces AJAX library (these isn\'t really all that important to the problem at hand - just some background).
Edge case answer (mostly so I can find it later):
Sending HTML document as String to api to generate PDFs.
For anyone that needs to convert the document.body to a String and them submit it via a POST to a service to convert the document to a PDF - IE8 doesn't support XMLSerializer
. That being said you can use: $(document.body).html();
for IE8.
/**
* Decides the method by which to turn the document.body into a string that we can post to the PDF Api.
* Most browsers support XMLSerializer, for others (ie8) use jquery's html method to generate a string.
* @param xmldom - document.body
* @return - string representation of the document body
*/
function serializeXml(xmldom){
if (typeof XMLSerializer != "undefined"){
return (new XMLSerializer()).serializeToString(xmldom);
} else {
return $(xmldom).html();
}
}
Call it with: var dom = serializeXml(document.body);