在javascript中使用datauri渲染图像

时间:2022-09-10 19:06:18

I am trying to load an image using AJAX that is sent as data uri. Everything works fine as long as image is < 32kb. Some of the images are large in size around 500 kb. I did some research on this and found that IE8 supports only images < 32kb to be loaded using datauri.

我正在尝试使用作为数据uri发送的AJAX加载图像。只要图像<32kb,一切正常。一些图像大小约为500 kb。我对此做了一些研究,发现IE8只支持使用datauri加载<32kb的图像。

Is there any workaround to load the image which is > 32kb or am i missing something here?

是否有任何解决方法来加载> 32kb的图像或我错过了什么?

3 个解决方案

#1


3  

Data URI scheme

数据URI方案

Internet Explorer 8: Microsoft has limited its support to certain "non-navigable" content for security reasons, including concerns that JavaScript embedded in a data URI may not be interpretable by script filters such as those used by web-based email clients. Data URIs must be smaller than 32 KiB in Version 8.[3] Data URIs are supported only for the following elements and/or attributes:[4]

Internet Explorer 8:出于安全原因,Microsoft限制其对某些“不可导航”内容的支持,包括担心嵌入在数据URI中的JavaScript可能无法被脚本过滤器(例如基于Web的电子邮件客户端使用的脚本过滤器)解释。版本8中的数据URI必须小于32 KiB。[3]仅支持以下元素和/或属性的数据URI:[4]

  • object (images only)
  • 对象(仅限图像)
  • img
  • IMG
  • input type=image
  • 输入类型=图像
  • link (data URI must be base64 encoded)
  • link(数据URI必须是base64编码的)
  • CSS declarations that accept a URL, such as background-image, background, list-style-type, list-style and similar.
  • 接受URL的CSS声明,例如background-image,background,list-style-type,list-style等。

Internet Explorer 9: Internet Explorer 9 does not have 32KiB limitation and allowed in broader elements.

Internet Explorer 9:Internet Explorer 9没有32KiB限制,允许使用更广泛的元素。

#2


0  

Yes, serve it as MHTML using some commentring tricks, described here and here.

是的,使用一些commentring技巧将其作为MHTML服务,在此处和此处描述。

#3


-1  

You could load the image data into a canvas element.
For IE8 you should have a look at How can I use the HTML5 canvas element in IE?

您可以将图像数据加载到canvas元素中。对于IE8,您应该看一下如何在IE中使用HTML5 canvas元素?

#1


3  

Data URI scheme

数据URI方案

Internet Explorer 8: Microsoft has limited its support to certain "non-navigable" content for security reasons, including concerns that JavaScript embedded in a data URI may not be interpretable by script filters such as those used by web-based email clients. Data URIs must be smaller than 32 KiB in Version 8.[3] Data URIs are supported only for the following elements and/or attributes:[4]

Internet Explorer 8:出于安全原因,Microsoft限制其对某些“不可导航”内容的支持,包括担心嵌入在数据URI中的JavaScript可能无法被脚本过滤器(例如基于Web的电子邮件客户端使用的脚本过滤器)解释。版本8中的数据URI必须小于32 KiB。[3]仅支持以下元素和/或属性的数据URI:[4]

  • object (images only)
  • 对象(仅限图像)
  • img
  • IMG
  • input type=image
  • 输入类型=图像
  • link (data URI must be base64 encoded)
  • link(数据URI必须是base64编码的)
  • CSS declarations that accept a URL, such as background-image, background, list-style-type, list-style and similar.
  • 接受URL的CSS声明,例如background-image,background,list-style-type,list-style等。

Internet Explorer 9: Internet Explorer 9 does not have 32KiB limitation and allowed in broader elements.

Internet Explorer 9:Internet Explorer 9没有32KiB限制,允许使用更广泛的元素。

#2


0  

Yes, serve it as MHTML using some commentring tricks, described here and here.

是的,使用一些commentring技巧将其作为MHTML服务,在此处和此处描述。

#3


-1  

You could load the image data into a canvas element.
For IE8 you should have a look at How can I use the HTML5 canvas element in IE?

您可以将图像数据加载到canvas元素中。对于IE8,您应该看一下如何在IE中使用HTML5 canvas元素?