Purpose of the crossorigin attribute…?

前端 未结 5 1275
慢半拍i
慢半拍i 2020-12-02 08:31

In both image and script tags.

My understanding was that you can access both scripts and images on other domains. So when does one use this attribute?

Is thi

5条回答
  •  北海茫月
    2020-12-02 09:13

    I've found out how to persuade Google Chrome to allow file:// references without throwing a cross-origin error.

    Step 1: Create a shortcut (Windows) or the equivalent in other operating systems;

    Step 2: Set the target to something like the following:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files

    That special command line argument, --allow-file-access-from-files, tells Chrome to let you use file:// references to web pages, images etc., without throwing cross-origin errors every time you try to transfer those images to an HTML canvas, for example. It works on my Windows 7 setup, but it's worth checking to see if it will work on Windows 8/10 and various Linux distros too. If it does, problem solved - offline development resumes as normal.

    Now I can reference images and JSON data from file:// URIs, without Chrome throwing cross-origin errors if I attempt to transfer image data to a canvas, or transfer JSON data to a form element.

提交回复
热议问题