检测 IE 中是否启用字体下载

发布于 2024-12-13 16:36:48 字数 533 浏览 1 评论 0原文

有没有办法检测 Internet Explorer 中的字体下载属性是否已禁用或启用?

目前,如果我要实现用于字体渲染的 @font-face 解决方案(font-squirrel 或 typekit 或其他),则所有浏览器都会播放良好除了(如果 Internet Explorer 禁用了“字体下载”选项) 。

这个设置可以在IE>中找到互联网选项>安全>自定义级别>下载>>字体下载>>启用/禁用。

如果我能检测到这个选项,我就可以回退到 javascript 方法。

这些解决方案不起作用,因为此选项实际上不会禁用该功能,它会阻止下载发生:

  • http://paulirish.com/2009/font-face-feature-detection/
  • http://www.lalit.org/ lab/javascript-css-font-detect/

编辑:我应该提到,我们不能不使用服务器端解决方案,它必须是纯粹的客户端脚本。

Is there a way to detect whether the font download property in internet explorer is disabled or enabled?

Currently if I were to implement an @font-face solution (font-squirrel or typekit or other) for font-rendering, all browsers will play nice except if internet explorer has its "Font Download" option disabled.

This setting can be found in IE > Internet Options > Security > Custom Level > Downloads > Font download > Enable/Disable.

If I can detect this option, I could fall back to javascript methods.

These solutions do not work as this option does not actually disable the feature, it prevents a download from occurring:

  • http://paulirish.com/2009/font-face-feature-detection/
  • http://www.lalit.org/lab/javascript-css-font-detect/

EDIT: I should mention that we cannot not use a server-side solution, it must be purely client-side scripting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

像你 2024-12-20 16:36:48

由于此功能会阻止下载发生,一个(相当肮脏的)解决方案是要求 IE 下载一种所谓的字体,该字体实际上是服务器上的一个简单脚本,其中包含例如。一个 cookie 说“好吧,他得到了字体”并返回一个空白页。当用户加载下一页时,如果 cookie 不存在,您将部署 Javascript 机制。

在此处输入图像描述

As this feature prevents a download from occurring, a (rather dirty) solution would be to ask IE to download a so-called font that is actually a simple script on your server that puts eg. a cookie saying “ok he gots the font” and returns a blank page. When the user loads the next page, you will deploy the Javascript machinery if the cookie isn't there.

enter image description here

も让我眼熟你 2024-12-20 16:36:48

我意识到这个问题已经很老了,但对于一些具有严格 IT 安全性的企业互联网用户来说,这个问题仍然存在。我研究了上面的解决方案和其他解决方案,但它们对我来说效果不佳,所以我找到了另一个不需要服务器端代码、没有 javascript 和 css 的解决方案。它本质上很神奇,但也有一些局限性。

限制 1:这仅适用于使用高数字代码点来显示图像的图标字体。它不适用于可读文本的字体。

限制 2:您必须找到适合替换您的自定义图标的标准 UTF-8 符号。

例如,如果您有用于显示星形符号的自定义字体,则合适的后备方案是 unicode 代码点 0x2605 ★。因此,在字体生成代码中,您需要将该代码点硬编码到星形图标的 css 类。如果您使用“grunt-webfont”,您将在 grunt 文件中执行以下操作:

webfont: {
    icons: {
        options: {
           codepoints: {
              'star': 0x2605
       ...
}}}}

星号是一个完美的例子;为您的精美图标找到合适的 UTF8 替代品可能很困难,因此这可能并不适合所有人。考虑到这个问题影响极少数用户,我们认为这是一个合适的透明解决方案,不会因为额外的 js/css/cookie 问题而影响普通用户。

I realize this question is old, but this problem still exists for some corporate internet users with strict IT security. I looked into the solutions above and others, but they didn't work well for me, so I found another solution that requires no server side code, no javascript, and no css. Its essentially magic, but it has some limitations.

Limitation 1: This will only work for icon-fonts that use high number codepoints to display images. It will not work for typeface fonts for readable text.

Limitation 2: You must find a standard UTF-8 symbol that is a suitable replacement for your custom icon.

For example, if you have a custom font that you use to display a star symbol, a suitable fallback for this would be unicode code point 0x2605 ★. So, in your font generation code, you would need to hard code that codepoint to your css class for your star icon. If you were using "grunt-webfont" you would do something like this in your grunt file:

webfont: {
    icons: {
        options: {
           codepoints: {
              'star': 0x2605
       ...
}}}}

The star is a perfect example; it may be challenging to find a suitable UTF8 replacement for your fancy icons so this may not work for everyone. Considering that this problem affects a very small number of users, we felt that this was a suitable transparent solution that did not impact regular users with extra js/css/cookie cruft.

陌生 2024-12-20 16:36:48

根据 @Zopieux 流程图,当禁用字体下载时,我能够使该脚本适用于 IE6-9,在我的例子中,该脚本适用于像其他公司内部网一样禁用此设置的客户端。

CSS:

@font-face {  
    font-family: 'TestFont';  
    src: url('/includes/font.php?type=eot');  
    src: url('/includes/font.php?type=eot#iefix') format('embedded-opentype'),  
     url('/includes/font.php?type=woff') format('woff'),
     url('/includes/font.php?type=ttf') format('truetype'),
     url('/includes/font.php?type=svg#UniversLTStd49LtUltraCn') format('svg');
    font-weight: normal;  
    font-style: normal;  
}  

PHP,当请求 font-face src url 时,它会提取此脚本,该脚本检查类型、设置 cookie 并提供所选的 webfont。如果启用了字体下载并且您没有重新路由到字体文件,IE 将抛出 @font-face 错误:

<?php
$type = $_REQUEST['type'];
$location = "Location: /includes/fonts/universltstd-lightultracn-webfont.".$type;

// create a cookie
setrawcookie("FontDownloaded", 1, time()+3600*24, '/');
header($location);

?>

JS,然后在客户端执行类似的操作来检查 cookie,并执行类似 cufon-yui.js 或 typeface.js 的替代方案:

$(function() {
    $('body').append('<span id="TestFont"/>');
    $('#TestFont').html('Testing').css({
        fontFamily: 'TestFont',
        opacity: 0
    });

    // find cookie
    bool = Boolean(getCookie('FontDownloaded')); // use your own cookie method

    if (!bool) {
        // implement @font-face fallback        
        Cufon.replace('.items', { fontFamily: 'NewFont' });
    }
    $('#TestFont').remove();
});

Based on @Zopieux flow chart, I was able to make this script work for IE6-9 when font-downloading is disabled, which in my case was for a client where like other corporate intranets have this setting disabled.

CSS:

@font-face {  
    font-family: 'TestFont';  
    src: url('/includes/font.php?type=eot');  
    src: url('/includes/font.php?type=eot#iefix') format('embedded-opentype'),  
     url('/includes/font.php?type=woff') format('woff'),
     url('/includes/font.php?type=ttf') format('truetype'),
     url('/includes/font.php?type=svg#UniversLTStd49LtUltraCn') format('svg');
    font-weight: normal;  
    font-style: normal;  
}  

PHP, when the font-face src url is requested, it pulls this script, which checks the type, sets the cookie, and serves the webfont of choice. If font-downloading is enabled and you do not re-route to the font file, IE will throw up an @font-face error:

<?php
$type = $_REQUEST['type'];
$location = "Location: /includes/fonts/universltstd-lightultracn-webfont.".$type;

// create a cookie
setrawcookie("FontDownloaded", 1, time()+3600*24, '/');
header($location);

?>

JS, then on the client side, do something like this to check for the cookie, and perform the alternative like cufon-yui.js or typeface.js:

$(function() {
    $('body').append('<span id="TestFont"/>');
    $('#TestFont').html('Testing').css({
        fontFamily: 'TestFont',
        opacity: 0
    });

    // find cookie
    bool = Boolean(getCookie('FontDownloaded')); // use your own cookie method

    if (!bool) {
        // implement @font-face fallback        
        Cufon.replace('.items', { fontFamily: 'NewFont' });
    }
    $('#TestFont').remove();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文