Size limit to javascript [node].nodeValue field?

前端 未结 4 1791
梦如初夏
梦如初夏 2020-12-21 08:05

I\'m receiving XML data via an AJAX call. One of the tags has a large amount of text, roughly 4000-5000 characters. In Firefox, the field is being truncated around the 3000t

4条回答
  •  猫巷女王i
    2020-12-21 08:27

    @Kooilnc has it right, 4k limit on text nodes in Firefox.

    You can work around it by doing this:

    function getNodeText(xmlNode) {
        if(!xmlNode) return '';
        if(typeof(xmlNode.textContent) != "undefined") return xmlNode.textContent;
        return xmlNode.firstChild.nodeValue;
    }
    
    text = getNodeText(document.getElementsByTagName("div").item(0));
    alert(text.length);
    

    See it in action here: http://jsfiddle.net/Bkemk/2/

    Function borrowed from here: http://www.quirksmode.org/dom/tests/textnodesize.html

提交回复
热议问题