【问题标题】:Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”) firefox webextensions内容安全策略:该页面的设置阻止了在内联(“script-src”)firefox webextensions 中加载资源
【发布时间】:2019-01-14 12:37:51
【问题描述】:

内容安全政策:页面设置阻止了内联资源(“script-src”)的加载。

尝试将 onclick 事件添加到侧边栏中的按钮时,在控制台中显示此错误

<html>
  <head>
    <meta charset="utf-8">
  </head>

<body>
  <div id = "content"></div>
  <script src="panel.js"></script>
<button id="createNewInstance" onclick="openDb()">New Category</button>
</body>

</html>

这是为什么呢?

【问题讨论】:

    标签: firefox-addon-webextensions


    【解决方案1】:

    您不能在 WebExtension 页面中使用内联脚本或定义事件处理程序。您必须在外部 JavaScript 文件中添加事件处理程序。

    panel.js

    document.getElementById("createNewInstance").addEventListener("click", openDb)
    

    【讨论】:

    • 它说: TypeError: document.getElementById(...) is null function openDb() { console.log("openDb ..."); } document.getElementById("createNewInstance").addEventListener("click", openDb); // const contentBox = document.querySelector("#createNewInstance"); //var createNewInstanceEl = window.document.getElementById("createNewInstance"); // createNewInstanceEl.onclick = openDb();
    猜你喜欢
    • 2020-12-17
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 2021-02-24
    相关资源
    最近更新 更多