您的位置:首页技术文章
文章详情页

javascript - html引入外部js文件保存拒绝加载脚本是怎么回事?

【字号: 日期:2023-03-28 16:52:23浏览:20作者:猪猪

问题描述

下面是报错信息:Refused to load the script ’http://*/js/track.js’ because it violates the following Content Security Policy directive: 'default-src https: data: ’unsafe-inline’ ’unsafe-eval’ ’self’ .qq.com .flzhan.com .gtimg.com .share.baidu.com .gtimg.cn .qlogo.cn img.hb.aicdn.com pub.idqqimg.com nsclick.baidu.com ajax.googleapis.com .qpic.cn code.jquery.com cdn.bootcss.com .sec.qq.com .sinaimg.cn wvjbscheme://* creativecommons.org www.w3.org purl.org tnm2.oa.com statics.dnspod.cn doksoft.com js.plus weixinping weixinpreinject weixin jsbridge'. Note that ’script-src’ was not explicitly set, so ’default-src’ is used as a fallback.

引入文件是这样引入的

<script type='text/javascript' src='http://****/js/track.js'></script>

HTML头部是这样

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN''http://www.w3.org/TR/html4/loose.dtd'><html ><head> <meta charset='utf-8'> <meta name='viewport' content='width=320,minimum-scale=0.5, maximum-scale=5, user-scalable=no'> <meta name='format-detection' content='telephone=no'>

我尝试过将js文件放到站内,引入站内的js文件也报这个错误,请问这是怎么回事呢?谢谢

问题解答

回答1:

Note that ’script-src’ was not explicitly set, so ’default-src’ is used as a fallback.从报错信息来看,你们的资源配置信息错了,把一些东西给屏蔽了。

<meta http-equiv='Content-Security-Policy' content='default-src ’self’ http://XX.XX.XX.XX '>//试试加上这个 地址是自己服务器地址

<meta http-equiv='Content-Security-Policy' content='default-src *; frame-src ’self’ wvjbscheme://*; style-src ’self’ http://*.xxx.com ’unsafe-inline’; script-src ’self’ ’unsafe-inline’ ’unsafe-eval’ http://*.xxx.com;'>//加强版 只要default和js的配置就好, 其他的看需要

标签: JavaScript
相关文章: