開發chrome插件報錯:Refused to execute inline event handler because it violates the following Content Security Policy directive


Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

原因是 Chrome 插件不支持在插件的 html 上寫內聯 js, 如果需要添加事件,可以再外聯 js 中寫入:

錯誤的寫法:

<div class="switch-box">
   <input class="switch-input" onchange="beautyUI()" type="checkbox" />
</div>

正確的寫法

<div class="switch-box">
   <input class="switch-input" value="beautyUI" type="checkbox" />
</div>
$(function () {
  $('.switch-input').change(function () {
    var value = $(this).val()
    if (value === 'beautyUI') {
      beautyUI()
    }
  })
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 vscode electron error (Refused to execute inline event handler because it violates the following Content Security Policy directive ... 和 Uncaught ReferenceError: process is not defined) Electron中Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Chrome插件在頁面上直接綁定JavaScript事件提示Refused to execute inline event handler because it violates the following Co 解決 Jenkins 中無法展示 HTML 樣式的問題,csp問題,Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Electron中提示:Refused to execute inline event handler because it violates iframe because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' Refused to load the script xxxxxx because it violates the following Content Security Policy directive:"script-src 'self' xxxxxxxxxxxxx" 瀏覽器安全問題 because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'style-src' was not explicitly set, so 'default-src' is used as a fallback.錯誤應該怎么解決? Refused to display because an ancestor violates the following Content Security問題簡單解決 because it violates the following Content Security Policy directive: "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'". Note that 'script-src' was not explicitly set, so 'default-s
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM