innerHTML的大小限制 [英] innerHTML size limit

查看:1234
本文介绍了innerHTML的大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用AJAX加载HTMLFILE成< D​​IV> 然后,我将需要在此运行jsMath。我的一切都与innerHTML的完成至今已经有一两个段落,也许表和/或图像。没什么特别的。

I want to use AJAX to load an htmlfile into a <div> I will then need to run jsMath on this. Everything I have done so far with innerHTML has been a paragraph or two, maybe a table and/or image. Nothing too fancy.

当我设置的innerHTML到外部25K文件,用各种复杂的CSS格式,可能会出现哪些潜在的问题? (感谢jsMath)我不认为这样做的任何其他方法,但需要知道是否有任何限制。

What potential problems may occur when I set innerHTML to an external 25k file, with all sorts of complex css formatting? (thanks to jsMath) I can't think of any other method of doing this, but need to know if there are any limitations.

在此先感谢。

- 戴夫

推荐答案

我不知道任何特定浏览器的大小限制,但如果您分配一个字符串,时间越长,65536,Chrome浏览器将它分解成许多 elem.childNodes ,所以你可能要遍历这些节点,将它们连接起来。

I don't know about any browser specific size limits, but if you assign a string longer that 65536, Chrome splits it into many elem.childNodes, so you might have to loop over these nodes and concatenate them.

运行下面的剪断在Chrome开发工具。它构建了一个160ķ字符串,但 theDivElement.childNodes [0] 被裁剪到65536个字符。

Run the below snipped in Chrome Dev Tools. It constructs a 160 k string, but theDivElement.childNodes[0] gets clipped to 65536 chars.

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

结果:(Chrome浏览器版本39.0.2171.95(64位),Linux Mint的17)

Result: (Chrome version 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

但在Firefox 的innerHTML 没有的内容分割成许多节点:(FF版本34.0,Linux Mint的17)

But in Firefox innerHTML doesn't split the contents 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"

所以,你需要考虑到不同的浏览器处理子节点不同,或许遍历所有子节点并连接。 (我注意到这一点,因为我试图用的innerHTML 来反向转义一个> 100K的HTML连接codeD字符串。)

So you'd need to take into account that different browsers handle childNodes differently, and perhaps iterate over all child nodes and concatenate. (I noticed this, because I tried to use innerHTML to unescape a > 100k HTML encoded string.)

事实上,在Firefox我可以创建一个的innerHTML-子节点[0] 长度167 772 160,通过循环来 I&LT; 24 上方。但是上面的某个地方本lenght,有一个 InternalError该:分配大小溢出错误

In fact, in Firefox I can create an innerHTML-childNodes[0] of length 167 772 160, by looping to i < 24 above. But somewhere above this lenght, there is an InternalError: allocation size overflow error.

这篇关于innerHTML的大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆