问答详情
源自:4-5 使用 Snippets 来辅助 Debugging

Snippets add import jQuery CORS

let script = document.createElement('script');

script.src="https://code.jquery.com/jquery-3.2.1.min.js";

script.integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=";

script.crossorigin="anonymous";

document.head.appendChild(script);


error:

Subresource Integrity: The resource 'https://code.jquery.com/jquery-3.2.1.min.js' has an integrity attribute, but the resource requires the request to be CORS enabled to check the integrity, and it is not. The resource has been blocked because the integrity cannot be enforced.

提问者:精慕门5330565 2022-11-07 16:48

个回答

  • 精慕门5330565
    2022-11-07 16:59:42

    let script = document.createElement('script');
    script.src="https://code.jquery.com/jquery-3.2.1.min.js";
    script.integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=";
    script.crossorigin="anonymous";
    document.head.appendChild(script);

    我尝试了一下,去掉integrity和crossorigin属性,就不再报CORS了...

    如下:

    let script = document.createElement('script');
    script.src="https://code.jquery.com/jquery-3.2.1.min.js";
    document.head.appendChild(script);