I don't know any size limits for a particular browser, but if you assign a string longer than 65536, Chrome breaks it into many elem.childNodes , so you may need to elem.childNodes over these nodes and merge them.
Run the Chrome Dev Tools utility described below. It builds a string of 160 k, but theDivElement.childNodes[0] gets bound to 65536 characters.
var longString = '1234567890'; for (var i = 0; i < 14; ++i) { longString = longString + longString; } console.log('The length of our long string: ' + longString.length); var elem = document.createElement('div'); elem.innerHTML = longString; var innerHtmlValue = elem.childNodes[0].nodeValue; console.log('The length as innerHTML-childNodes[0]: ' + innerHtmlValue.length); console.log('Num child nodes: ' + elem.childNodes.length);
Result: (version for Chrome 39.0.2171.95 (64-bit), Linux Mint 17)
The length of our long string: 163840 The length as innerHTML-childNodes[0]: 65536 Num child nodes: 3
But in Firefox innerHTML content is not broken into many nodes: (FF version 34.0, Linux Mint 17)
"The length of our long string: 163840" "The length as innerHTML-childNodes[0]: 163840" "Num child nodes: 1"
So, you need to consider that different browsers handle childNodes differently and possibly childNodes over all the child nodes and merge. (I noticed this because I tried using innerHTML for unescape> 100k HTML encoded string.)
In fact, in Firefox I can create innerHTML-childNodes[0] length 167 772 160 by going to i < 24 above. But somewhere above this length, there is an InternalError: allocation size overflow error.
KajMagnus Dec 18 '14 at 11:33 2014-12-18 11:33
source share