Home > Web Front-end > CSS Tutorial > Why Can\'t I Use @font-face Fonts from a Subdomain in Firefox?

Why Can\'t I Use @font-face Fonts from a Subdomain in Firefox?

Susan Sarandon
Release: 2024-11-15 21:31:03
Original
983 people have browsed it

Why Can't I Use @font-face Fonts from a Subdomain in Firefox?

Cross-Domain @font-face Blocking

In an attempt to establish a font repository, you've encountered an issue where @font-face declarations in a subdomain are accessible only within that subdomain. Firebug confirms the successful loading of the font-face.css file, leaving you puzzled about the font loading failure on other sites.

Firefox's Cross-Domain Restriction

The root cause lies in Firefox's security measure. It prevents the embedding of fonts across domains, including subdomains. This measure aims to safeguard against potential malicious activities.

htaccess File Modification

To overcome this restriction in Firefox, modify the subdomain's top-level .htaccess file by adding the following code:

<FilesMatch "\.(ttf|ttc|otf|eot|woff)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>
Copy after login

This code adds a header to the response that permits cross-origin font loading.

Restricting Access

While you initially sought to grant yourself exclusive access to the font repository, the W3C spec for Access-Control-Allow-Origin only allows a wildcard "*" or a specific domain. Further research is required to determine if there are options for implementing more granular control over access.

The above is the detailed content of Why Can\'t I Use @font-face Fonts from a Subdomain in Firefox?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template