很抱歉打扰您,我正在开发我的个人网站并尝试集成 Google map (感谢 codepen 提供的出色模板)。
但我必须面对反复出现的 CSP 错误消息,导致 map 无法加载:
Refused to load the script 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBlSsS5JzdJLsuMEY24xeLAZOc7JAH6sr8' because it violates the following Content Security Policy directive: "script-src 'self' www.google-analytics.com".
我在提出问题之前进行了研究,因为这对很多人来说似乎是一个问题。我尝试了一切,包括删除 Google Analytics 脚本并添加以下内容:
<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://apis.google.com https://maps.googleapis.com https://maps.gstatic.com www.google-analytics.com ajax.googleapis.com; object-src 'self'">
但这并没有改变任何事情。我的 map 无法加载,这让我很恼火!
你知道我做错了什么吗?非常感谢你的帮助 ! (如果需要,我可以实时向您展示错误,但我不想在这里“推广”我的网站)
最佳答案
.htaccess
文件的第 479 行显示:
Header set Content-Security-Policy "script-src 'self' www.google-analytics.com"
不确定您的 meta
标记可以覆盖此设置。
您可能应该修改 .htaccess
文件中的该行,以包含其他来源(对于 Google map ,“https://maps.googleapis.com
“)。
关于javascript - 一个简单的网站违反了内容安全策略指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723585/