简体   繁体   English

如何将 js 中的 crossorigin='anonymous' 添加到脚本中

[英]how to add crossorigin='anonymous' from js to script


            script.type = 'text/javascript';
            script.async = true;
            script.src = url;
            script.crossorigin="anonymous"

            const element = document.getElementsByTagName('script')[0];

            element.parentNode.insertBefore(script, element);

            script.onload = () => {
                resolve(script);
            }

As you can see, I am setting crossorigin in there, but it turns out that when I see the html , script doesn't have crossorigin .如您所见,我在那里设置crossorigin ,但事实证明,当我看到html时,脚本没有crossorigin Basically, I don't want to have opaque response, so how do I set crossorigin correctly?基本上,我不想有opaque的响应,那么如何正确设置crossorigin呢?

Wrong attribute name.错误的属性名称。 It's crossOrigin in camelCase在 camelCase 中是crossOrigin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM