简体   繁体   English

Javascript抛出:拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script-src'self'

[英]Javascript throwing : Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'

I'm newbie in google chrome extention delveopment. 我是google chrome extention开发的新手。 I'm trying to develop a simple extension and i keep getting the error above. 我正在尝试开发一个简单的扩展,我不断收到上面的错误。

my manifest: 我的清单:

{
  "name": "set my favourties",
  "description" : "just another super awesome plugin",
  "version" : "0.1", 
    "background": {
    "page": "backround.html"
  },

   "manifest_version": 2,
    "content_security_policy": "script-src 'self' https://www.google.com; object-src 'self'",

   "browser_action" :{
     "popup" : "popup.html",
     "default_icon" : "icon.gif"
     },

     "permissions" : ["notifications"]
 }

the html code: HTML代码:

<html>
<head>
<script src = "backround.js">

</script>
</head>
<body onload = "loadHandler()">

</body>
</html>

and the js: 和js:

  function loadHandler(){
  window.webkitNotifications.createNotification("icon.gif","Plugin Loaded","it was loaded").show();

   }

thanks in advance 提前致谢

Nir 尼尔

If this wasn't a Chrome extension, you could add 'unsafe-inline' to the list of acceptable places to load scripts from, 如果这不是Chrome扩展程序,您可以将'unsafe-inline'添加到可加载脚本的可接受位置列表中, but you should avoid using inline event handlers at all. 但你应该避免使用内联事件处理程序。

Replace (in the HTML): 替换(在HTML中):

onload = "loadHandler()"

with (in the script): with(在脚本中):

window.addEventListener('load', loadHandler);

暂无
暂无

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

相关问题 内联脚本,因为它违反了以下内容安全策略指令:“script-src 'self'” - Inline script because it violates the following Content Security Policy directive: “script-src 'self'” 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“default-src 'self'” - Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'" Chrome 扩展策略错误:拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令 - Chrome extension policy error: Refused to execute inline event handler because it violates the following Content Security Policy directive 我不断收到错误“拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令 - I keep getting the error "Refused to execute inline event handler because it violates the following Content Security Policy directive 因为它违反了以下内容安全策略指令:“script-src &#39;self&#39; blob:”。 请注意,&#39;script-src-elem&#39; 没有明确设置, - because it violates the following Content Security Policy directive: "script-src 'self' blob:". Note that 'script-src-elem' was not explicitly set, 拒绝加载脚本,因为它违反了以下内容安全策略指令:“style-src 'self' 'unsafe-inline' - Refused to load the script because it violates the following Content Security Policy directive: "style-src 'self' 'unsafe-inline' 拒绝执行内联脚本,因为它违反了以下内容安全策略指令 - Refused to execute inline script because it violates the following Content Security Policy directive Firebase Chrome 扩展 - 拒绝执行内联脚本,因为它违反了以下内容安全策略指令 - Firebase Chrome Extension - Refused to execute inline script because it violates the following Content Security Policy directive Cordova 错误:拒绝执行内联脚本,因为它违反了以下内容安全策略指令 - Cordova error: Refused to execute inline script because it violates the following Content Security Policy directive 拒绝加载脚本,因为它违反了以下内容安全策略指令 - Refused to load the script because it violates the following Content Security Policy directive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM