57

我想在我正在创建的 HTML/JavaScript 应用程序中显示“刷新”符号,但我不想发出任何 HTTP 请求来加载图像。我怎样才能在所有主要浏览器中可靠地做到这一点?

我能找到的最接近的 Unicode 值是:↺ ( ↺),但箭头指向错误的方向。

是否有另一个有效的 Unicode 值?

是否有有效的 Webdings 字体?(它们通常不适用于 Opera 和 Firefox。)

有没有办法使用该 JS 中的字符串提供的base64 图像源在 JavaScript 中创建图像?

编辑:

原因不是开销。正在创建的应用程序必须自包含在单个 javascript 文件中,没有任何其他依赖项。它是一种开发实用程序,可以添加到任何项目中,无需网络。

4

8 回答 8

120

如果您发现字符↻(↻),即 U+21BB CLOCKWISE OPEN CIRCLE ARROW,可以满足您的需要(其箭头的放置方式可能与常见的重新加载图标不同),那么您可以相当安全地使用它:

.reload {
  font-family: Lucida Sans Unicode
}
<span class=reload>&#x21bb;</span>

Lucida Sans Unicode 字体包含该符号,并且它几乎可以在您现在可以找到的任何 Windows 系统中使用。根据MS info,它甚至包含在 Windows 98(和 Windows 95 plus)中。

可以合理地期望 Windows 以外的系统具有某种字体的符号,并且具有知道如何从其中一些字体中获取它的浏览器。包含它的字体具有相当相似的形状。(但如果符号需要在风格上与文档文本匹配,则需要更详细地研究情况并尝试确保字体列表或“字体堆栈”中的所有字体都包含它。)

于 2012-11-20T14:06:19.620 回答
61

Unicode 字符

至少有两个 Unicode 字符可以用作刷新重新加载图标:

  • 顺时针间隙圆箭头
    U+27F3
    ⟳</li>
  • 顺时针开圆箭头
    U+21BB
    ↻</li>

第一个不会出现在 iOS 7 或 8 或 9 的 Safari 或 Chrome 中。因此,鉴于此,并给出Paul D. White 的答案,我建议使用第二个CLOCKWISE OPEN CIRCLE ARROW

提示:如果您是 Mac 用户,请获取免费应用程序UnicodeChecker。您可以按名称搜索字符,并且可以看到包含该字符字形的字体列表(在您的特定 Mac 上)。

图标字体

一些字体是用可缩放的基于矢量的图标代替常规字符字形创建的。

于 2013-04-10T00:04:19.560 回答
17

如果浏览器支持从 Base64 字符串加载图像数据,您可以使用img并将其设置src为以下格式:

data:[<mediatype>][;base64],<data>

例子:

var img = document.getElementById("yourImage");
img.src = "data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
<img id="yourImage" />

于 2012-11-20T13:44:39.283 回答
15

与您的 Unicode 字符等效的顺时针方向是&#8635;, ↻ (尽管正如David C. Bishop在评论中指出的那样,Chromebook 使用#27f2, ⟳</a>)。

使用文本字符是一种选择,但 Windows XP 可能不显示该字符(取决于您使用的字符和显示它的字体)。 @Jukka K. Korpela 注意到这个字符包含在 Lucida Sans Unicode 字体中,因此即使在 Windows XP 中它也应该可以正常工作。

就 Wingdings 字体而言,为避免 HTTP 请求,您需要确信相关字体将安装在最终用户的计算机上。我认为没有通用的跨平台 Wingdings 字体(不过我可能完全错了)。

您确实可以使用 JavaScript 从包含图像的 base64 编码表示的字符串创建图像。你可以这样做:

var image = new Image();
image.src = 'data:image/gif;base64,' + BASE64_ENCODED_STRING; // Replace gif with whatever image format it actually is

不过,data-uri 在 Internet Explorer 8 和更早版本中可能无法很好地工作,Windows XP 用户可能会被卡住。(而且你实际上并不需要 JavaScript:你可以在你的页面中放置一个带有该属性的<img>标签。)src

于 2012-11-20T13:45:04.653 回答
9

Unicode 6 字符

'顺时针向下和向上打开圆形箭头' (U+1F503)

可悲的是,字形的字体支持不是最好的,所以“所有主要浏览器”可能是一个延伸...... :-/

于 2016-03-07T00:52:25.133 回答
8

.refresh {
  display: inline-block;
  transform: rotate(90deg);
}
<span>↻&lt;/span>
<hr>
<span class="refresh">↻&lt;/span>

于 2019-01-02T13:08:56.143 回答
2

您提到“所有主要浏览器”,所以让我们假设:

  1. 不是每个人都有 javascript
  2. 不是每个人都可以嵌入字体(黑莓等)
  3. 不是每个人都支持所有 UNCODE 表示(Windows XP)
  4. 不是每个人都支持内联数据 uri (IE7-)

那么还剩下什么?我建议使用符合 HTML1 的IMG元素,它也会在首次加载后被缓存:

<img src="/refresh.gif" alt="refresh">

它可以在我所知道的每一个浏览器中运行,除了 LYNX 和其他纯文本浏览器。但他们会改为显示“刷新”,所以没关系。

如果您真的想避免对“现代”浏览器的额外 2 字节请求,您可以对 IE7 使用条件注释:

<!--[if lte IE 7]>
<img src="refresh.gif" alt="refresh">
<![endif]-->

其余的都是这样的:

<img src="data:image/gif;base64,..." alt="refresh">

如果您想要最新的东西,您可以使用 CSS 框阴影(演示):

.refresh{
    border-radius: 0;
    display: inline-block;
    width: 1px;
    height: 1px;
    box-shadow: 0px 0px rgba(0,0,0,0),0px 1px rgba(0,0,0,0),0px 2px rgba(0,0,0,0),0px 3px rgba(0,0,0,0),0px 4px rgba(0,0,0,0),0px 5px rgba(0,0,0,0),0px 6px rgba(0,0,0,0),0px 7px rgba(0,0,0,0),0px 8px rgba(0,0,0,0),0px 9px rgba(0,0,0,0),0px 10px rgba(0,0,0,0),0px 11px rgba(0,0,0,0),0px 12px rgba(0,0,0,0),0px 13px rgba(0,0,0,0),0px 14px rgba(0,0,0,0),0px 15px rgba(0,0,0,0),1px 0px rgba(0,0,0,0),1px 1px rgba(0,0,0,0),1px 2px rgba(0,0,0,0),1px 3px rgba(0,0,0,0),1px 4px rgba(0,0,0,0),1px 5px rgba(0,0,0,0),1px 6px rgba(0,0,0,0),1px 7px rgba(0,0,0,0),1px 8px rgba(0,0,0,0),1px 9px rgba(0,0,0,0),1px 10px rgba(0,0,0,0),1px 11px rgba(0,0,0,0),1px 12px rgba(0,0,0,0),1px 13px rgba(0,0,0,0),1px 14px rgba(0,0,0,0),1px 15px rgba(0,0,0,0),2px 0px rgba(0,0,0,0),2px 1px rgba(0,0,0,0),2px 2px rgba(0,0,0,0),2px 3px rgba(0,0,0,0),2px 4px rgba(0,0,0,0),2px 5px rgba(0,0,0,0.06),2px 6px rgba(0,0,0,0.55),2px 7px rgba(0,0,0,0.79),2px 8px rgba(0,0,0,0.86),2px 9px rgba(0,0,0,0.86),2px 10px rgba(0,0,0,0.65),2px 11px rgba(0,0,0,0.31),2px 12px rgba(0,0,0,0),2px 13px rgba(0,0,0,0),2px 14px rgba(0,0,0,0),2px 15px rgba(0,0,0,0),3px 0px rgba(0,0,0,0),3px 1px rgba(0,0,0,0),3px 2px rgba(0,0,0,0),3px 3px rgba(0,0,0,0),3px 4px rgba(0,0,0,0.25),3px 5px rgba(0,0,0,0.83),3px 6px rgba(0,0,0,0.86),3px 7px rgba(0,0,0,0.83),3px 8px rgba(0,0,0,0.69),3px 9px rgba(0,0,0,0.74),3px 10px rgba(0,0,0,0.86),3px 11px rgba(0,0,0,0.86),3px 12px rgba(0,0,0,0.6),3px 13px rgba(0,0,0,0.06),3px 14px rgba(0,0,0,0),3px 15px rgba(0,0,0,0),4px 0px rgba(0,0,0,0),4px 1px rgba(0,0,0,0),4px 2px rgba(0,0,0,0),4px 3px rgba(0,0,0,0.25),4px 4px rgba(0,0,0,0.83),4px 5px rgba(0,0,0,0.83),4px 6px rgba(0,0,0,0.43),4px 7px rgba(0,0,0,0),4px 8px rgba(0,0,0,0),4px 9px rgba(0,0,0,0),4px 10px rgba(0,0,0,0.13),4px 11px rgba(0,0,0,0.69),4px 12px rgba(0,0,0,0.86),4px 13px rgba(0,0,0,0.6),4px 14px rgba(0,0,0,0),4px 15px rgba(0,0,0,0),5px 0px rgba(0,0,0,0),5px 1px rgba(0,0,0,0),5px 2px rgba(0,0,0,0),5px 3px rgba(0,0,0,0.69),5px 4px rgba(0,0,0,0.86),5px 5px rgba(0,0,0,0.25),5px 6px rgba(0,0,0,0),5px 7px rgba(0,0,0,0),5px 8px rgba(0,0,0,0),5px 9px rgba(0,0,0,0),5px 10px rgba(0,0,0,0),5px 11px rgba(0,0,0,0),5px 12px rgba(0,0,0,0.69),5px 13px rgba(0,0,0,0.86),5px 14px rgba(0,0,0,0.25),5px 15px rgba(0,0,0,0),6px 0px rgba(0,0,0,0),6px 1px rgba(0,0,0,0),6px 2px rgba(0,0,0,0.13),6px 3px rgba(0,0,0,0.86),6px 4px rgba(0,0,0,0.6),6px 5px rgba(0,0,0,0),6px 6px rgba(0,0,0,0),6px 7px rgba(0,0,0,0),6px 8px rgba(0,0,0,0),6px 9px rgba(0,0,0,0),6px 10px rgba(0,0,0,0),6px 11px rgba(0,0,0,0),6px 12px rgba(0,0,0,0.13),6px 13px rgba(0,0,0,0.86),6px 14px rgba(0,0,0,0.65),6px 15px rgba(0,0,0,0),7px 0px rgba(0,0,0,0),7px 1px rgba(0,0,0,0),7px 2px rgba(0,0,0,0.43),7px 3px rgba(0,0,0,0.86),7px 4px rgba(0,0,0,0.31),7px 5px rgba(0,0,0,0),7px 6px rgba(0,0,0,0),7px 7px rgba(0,0,0,0),7px 8px rgba(0,0,0,0),7px 9px rgba(0,0,0,0),7px 10px rgba(0,0,0,0),7px 11px rgba(0,0,0,0),7px 12px rgba(0,0,0,0),7px 13px rgba(0,0,0,0.75),7px 14px rgba(0,0,0,0.83),7px 15px rgba(0,0,0,0),8px 0px rgba(0,0,0,0),8px 1px rgba(0,0,0,0.43),8px 2px rgba(0,0,0,0.69),8px 3px rgba(0,0,0,0.86),8px 4px rgba(0,0,0,0.6),8px 5px rgba(0,0,0,0.31),8px 6px rgba(0,0,0,0),8px 7px rgba(0,0,0,0),8px 8px rgba(0,0,0,0),8px 9px rgba(0,0,0,0),8px 10px rgba(0,0,0,0),8px 11px rgba(0,0,0,0),8px 12px rgba(0,0,0,0),8px 13px rgba(0,0,0,0.69),8px 14px rgba(0,0,0,0.86),8px 15px rgba(0,0,0,0),9px 0px rgba(0,0,0,0),9px 1px rgba(0,0,0,0.48),9px 2px rgba(0,0,0,0.86),9px 3px rgba(0,0,0,0.86),9px 4px rgba(0,0,0,0.86),9px 5px rgba(0,0,0,0.13),9px 6px rgba(0,0,0,0),9px 7px rgba(0,0,0,0),9px 8px rgba(0,0,0,0),9px 9px rgba(0,0,0,0),9px 10px rgba(0,0,0,0),9px 11px rgba(0,0,0,0),9px 12px rgba(0,0,0,0),9px 13px rgba(0,0,0,0.75),9px 14px rgba(0,0,0,0.83),9px 15px rgba(0,0,0,0),10px 0px rgba(0,0,0,0),10px 1px rgba(0,0,0,0),10px 2px rgba(0,0,0,0.79),10px 3px rgba(0,0,0,0.86),10px 4px rgba(0,0,0,0.6),10px 5px rgba(0,0,0,0),10px 6px rgba(0,0,0,0),10px 7px rgba(0,0,0,0),10px 8px rgba(0,0,0,0),10px 9px rgba(0,0,0,0),10px 10px rgba(0,0,0,0),10px 11px rgba(0,0,0,0),10px 12px rgba(0,0,0,0.13),10px 13px rgba(0,0,0,0.86),10px 14px rgba(0,0,0,0.65),10px 15px rgba(0,0,0,0),11px 0px rgba(0,0,0,0),11px 1px rgba(0,0,0,0),11px 2px rgba(0,0,0,0.38),11px 3px rgba(0,0,0,0.83),11px 4px rgba(0,0,0,0.06),11px 5px rgba(0,0,0,0),11px 6px rgba(0,0,0,0),11px 7px rgba(0,0,0,0),11px 8px rgba(0,0,0,0),11px 9px rgba(0,0,0,0),11px 10px rgba(0,0,0,0),11px 11px rgba(0,0,0,0),11px 12px rgba(0,0,0,0.69),11px 13px rgba(0,0,0,0.86),11px 14px rgba(0,0,0,0.25),11px 15px rgba(0,0,0,0),12px 0px rgba(0,0,0,0),12px 1px rgba(0,0,0,0),12px 2px rgba(0,0,0,0),12px 3px rgba(0,0,0,0.31),12px 4px rgba(0,0,0,0),12px 5px rgba(0,0,0,0),12px 6px rgba(0,0,0,0.25),12px 7px rgba(0,0,0,0),12px 8px rgba(0,0,0,0),12px 9px rgba(0,0,0,0),12px 10px rgba(0,0,0,0.13),12px 11px rgba(0,0,0,0.69),12px 12px rgba(0,0,0,0.86),12px 13px rgba(0,0,0,0.6),12px 14px rgba(0,0,0,0),12px 15px rgba(0,0,0,0),13px 0px rgba(0,0,0,0),13px 1px rgba(0,0,0,0),13px 2px rgba(0,0,0,0),13px 3px rgba(0,0,0,0),13px 4px rgba(0,0,0,0),13px 5px rgba(0,0,0,0.06),13px 6px rgba(0,0,0,0.83),13px 7px rgba(0,0,0,0.83),13px 8px rgba(0,0,0,0.69),13px 9px rgba(0,0,0,0.75),13px 10px rgba(0,0,0,0.86),13px 11px rgba(0,0,0,0.86),13px 12px rgba(0,0,0,0.6),13px 13px rgba(0,0,0,0.06),13px 14px rgba(0,0,0,0),13px 15px rgba(0,0,0,0),14px 0px rgba(0,0,0,0),14px 1px rgba(0,0,0,0),14px 2px rgba(0,0,0,0),14px 3px rgba(0,0,0,0),14px 4px rgba(0,0,0,0),14px 5px rgba(0,0,0,0.13),14px 6px rgba(0,0,0,0.55),14px 7px rgba(0,0,0,0.79),14px 8px rgba(0,0,0,0.86),14px 9px rgba(0,0,0,0.86),14px 10px rgba(0,0,0,0.65),14px 11px rgba(0,0,0,0.31),14px 12px rgba(0,0,0,0),14px 13px rgba(0,0,0,0),14px 14px rgba(0,0,0,0),14px 15px rgba(0,0,0,0),15px 0px rgba(0,0,0,0),15px 1px rgba(0,0,0,0),15px 2px rgba(0,0,0,0),15px 3px rgba(0,0,0,0),15px 4px rgba(0,0,0,0),15px 5px rgba(0,0,0,0),15px 6px rgba(0,0,0,0),15px 7px rgba(0,0,0,0),15px 8px rgba(0,0,0,0),15px 9px rgba(0,0,0,0),15px 10px rgba(0,0,0,0),15px 11px rgba(0,0,0,0),15px 12px rgba(0,0,0,0),15px 13px rgba(0,0,0,0),15px 14px rgba(0,0,0,0),15px 15px rgba(0,0,0,0);
}
于 2012-11-20T13:57:36.013 回答
-1

我认为这个图标会对你有所帮助。

编码

 - HTML Entity (decimal)    &#128472;
 - HTML Entity (hex)    &#x1f5d8;
于 2020-11-12T06:26:59.310 回答