首页 > 解决方案 > Extension Comment

问题描述

I'm creating an extension for google chrome that when the user clicks the "Copy!" button, execute this function on the web page

标签: html

解决方案


onclick="execute()"这不会运行,因为您不能JavaScript在 html 文件中使用内联来进行 chrome 扩展。

因此尝试click使用 JavaScript 在复制按钮上添加事件侦听器,如下所示:

document.addEventListener('DOMContentLoaded', function () {
      document.querySelector('input').addEventListener('click', execute);      
});

推荐阅读