首页 > 解决方案 > Popup.js 不适用于 Chrome 扩展

问题描述

目前我正在开发一个 chrome 扩展,并且使用 popup.html 我无法让 popup.js 工作

popup.html

<!DOCTYPE html>
<html>
  <head>
    <title>Title</title>
  </head>

  <body style="width: 15rem; height: 15rem">
    <div class="container-fluid" style="padding: 10px"> 
        <input id="url" />
        <button type="button" id="newDetails">Submit</button>
    </div>
    <script src="./popup.js"></script>
  </body>
</html>

popup.js

console.log("Hello")
let btn = document.getElementById("newDetails");
btn.onclick = function () {
  console.log("Clicked!");
};

我已经看过很多问题/答案(例如thisthisthis),但没有一个能够解决我的问题。

先感谢您!

标签: javascriptgoogle-chrome-extension

解决方案


解决!吴昊在原帖评论中回答。

需要检查弹出窗口的控制台与浏览器控制台。您可以通过右键单击扩展并检查它来做到这一点。


推荐阅读