Solve the problem of cross-origin access To icon font fonts by Firefox and ie9

Source: Internet
Author: User
Tags subdomain name

What is cross-origin access and why is there a cross-origin restriction? Everything has to begin with the same-source policy of the browser.

Same-origin policy: Is the core and basic security function of the browser. If the same-origin policy is missing, the normal function of the browser may be affected. It can be said that the Web is built on the same-origin policy, the browser is only an implementation of the same-source policy.

Same-origin policy of the browser: Restrict "document" or scripts from different sources to read or set certain attributes for the current "document. The existence of the same-origin policy limits that the "Source" script from a can only operate the DOM of the "same-origin" page, and the "cross-source" operation will be rejected for the page from B.

What is the same origin? "Img.company.com" and "agent.company.com" are not the same origins? For a long time, I thought these two domains are all subdomains of "company.com", which is the same source. This is actually wrong.

Same Source: Same host (same domain name, subdomain name, or IP address), same port number, and same protocol.

URL Same source? Cause
Http://agent.soufun.com/dir1/a.aspx Yes  
Http://agent.soufun.com/dir2/a.aspx Yes  
Https://agent.soufun.com/secure.htm No Different protocols
Http://agent.soufun.com: 81/dir2/a. aspx No Different ports
Http://img.soufun.com/dir/a.jpg No Different subdomains

 

Icon font: Currently, mainstream browsers (including IE6) support CSS 3 custom fonts (@ font-face), so you can try to use font to replace various icons of the Image Display website. This advantage is because it is a vector, the amplification is not distorted, the size is small, the disadvantage is also very obvious, that is, the font at the same time can only be monochrome.

After the function is implemented, the IE is displayed properly (left), but the Firefox Font is not displayed (right ). The following error is reported on the Firefox firebug console:Cross-Source request blocked: Same-source policy does not allow reading http://img.company.com/secondhouse/image/magentnew/styles/fonts20140704/icomoon.woff? Remote resources on ivldoa. You can move resources to the same domain name or enable CORS to solve this problem."

Why is ie different from Firefox? According to the information, "Firefox and ie9 do not support cross-origin access to the icon Font font ", you must configure the header parameter "access-control-allow-origin" on the server where the font file is located to allow the current domain name. In addition, after verification, you must set the parameter "access-control-allow-origin" to "*". the current domain name is not allowed. I do not know why.

How to add the specific configuration? The method is unknown because the O & M personnel helped to configure the configuration. For details, refer to "cross-origin access To icon font fonts in Firefox and ie9". the core is to add the response output of "access-control-allow-origin. To determine the feasibility of the scheme, I used Fiddler to intercept the HTTP Response and add a header. For details, refer to "two methods for setting HTTP Response Headers in Fiddler". again, I felt the powerful functions of Fiddler.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.