如何在HTML文件中编码图像数据? [英] How to encode image data within an HTML file?

查看:95
本文介绍了如何在HTML文件中编码图像数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够输出包含图像的HTML文件(在文件本身内)。通过谷歌搜索,我遇到了几种方法来做到这一点:


  • javascript:imageData < IMG SRC =data:image / gif; base64,[...]>< / li> code

  • < object ...> 标记(尽管这使用数据URI,因此可以继承相同的限制)



但我不知道浏览器支持哪种方式,或者是否有其他选择。



任何有这方面实践经验的人都可以给我建议吗?感谢。

解决方案

关于浏览器支持,来自 Wikipedia


数据URI目前支持
以下网页浏览器:




  • Gecko及其衍生产品,例如Mozilla Firefox
  • Opera

  • KDE,通过KIO输入/输出系统。这允许KDE浏览器Konqueror支持数据URI。

  • Safari;虽然Safari的渲染引擎WebKit是Konqueror的KHTML引擎的衍生产品,但Mac OS X不共享KIO从属体系结构,因此不会共享这些实现。

  • 适用于iPhone的Safari; li>
  • Google Chrome

  • Internet Explorer 8;出于安全原因,微软对某些不可导航内容提供了有限的支持,例如在标签和CSS规则中,包括担心嵌入在数据URI中的JavaScript可能无法通过基于Web的电子邮件所使用的脚本过滤器来解释客户端。数据URI必须小于32k。

  • The World Browser;是一个IE浏览器,它具有对数据URI方案的内置支持。

    $ b IE不处理 < object> 标记正确,请参阅此处了解更多详情。简单地说,你不能相信IE来显示图像。



    javascript:imageData 也不好因为它被用于很多跨站脚本攻击。



    有许多关于 web ,他们都得出结论,没有好的通用方法来嵌入图像。如果您只需要支持一部分浏览器,则数据uri可能会工作,或者是数据uri和javascript的组合。


    I'd like to be able to output an HTML file which includes an image (within the file itself). By Googling, I've come across a couple of ways to do this:

    • javascript:imageData
    • a data URI such as <IMG SRC="data:image/gif;base64,[...]">
    • <object ... > tag (although this uses a data URI, so may inherit the same limitations)

    But I don't know which is better supported by browsers, or if there are other alternatives.

    Can anyone with some practical experience of this offer me advice? Thanks.

    解决方案

    In regards to browser support, from Wikipedia:

    Data URIs are currently supported by the following web browsers:

    • Gecko and its derivatives, such as Mozilla Firefox
    • Opera
    • KDE, through the KIO input/output system. This allows the KDE browser, Konqueror to support data URIs.
    • Safari; although Safari's rendering engine, WebKit, is a derivative of Konqueror's KHTML engine, Mac OS X does not share the KIO slaves architecture so the implementations are not shared.
    • Safari for the iPhone;
    • Google Chrome
    • Internet Explorer 8; Microsoft has limited support to certain "non-navigable" content, such as in tags and CSS rules, 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 32k.
    • TheWorld Browser; is an IE shell browser which has a built-in support for Data URI scheme

    IE does not handle the <object> tag correctly, see here for more details. Briefly, you can't trust IE to display images from it.

    The javascript:imageData is also not well-supported, since it is used in a lot of cross site scripting attacks.

    There are many discussions of this on the web, and they all come to the conclusion that there is no good universal way to embed images. If you only need to support a subset of browsers, the data uri may work, or a combination of data uri and javascript.

    这篇关于如何在HTML文件中编码图像数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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