我需要时不时地使用JQuery来调试或修改网页。我打开开发者工具,在控制台中输入
(function()
{
var s=document.createElement('script');
s.setAttribute('src','https://code.jquery.com/jquery-2.1.1.min.js');
s.setAttribute('type','text/javascript');
document.getElementsByTagName('head')[0].appendChild(s);
jQuery.noConflict();
})();
但是 Chrome 说
Refused to load the script 'https://code.jquery.com/jquery-2.1.1.min.js' because it violates the following Content Security Policy directive: "script-src 'none'".
我了解内容安全策略有助于防止跨站点脚本编写。但我希望能够加载 JQuery。
如何将 JQuery 加载到任何页面?
最佳答案
如果页面具有该 CSP 指令,则不能(在支持 CSP 的浏览器上);页面所有者已将其锁定。如果您确实需要调试该页面,请修改服务器以不发送 CSP header 或允许来自 https://code.jquery.com
的脚本。
关于javascript - 手动加载JQuery而不触发内容安全策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28712272/