[removed] Replacement for XMLSerializer.serializeToString()?

前端 未结 4 1144
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 03:50

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).

4条回答
  •  一生所求
    2020-12-10 04:39

    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);

提交回复
热议问题