Javascript Chrome插件文本转发

Javascript Chrome插件文本转发,javascript,html,css,google-chrome,Javascript,Html,Css,Google Chrome,我正在开发一个Chrome插件,需要帮助将数据从popup.html转发到background.js 我想将文本粘贴到弹出窗口中的输入文本框中,并能够在后台脚本中使用它,目前,它应该只追加文本,但我计划使用文本操作来自动化“数据库”输入工作。 从excel通过我的插件到某些表单 Manifest.json Popup.html background.js 如果您正在尝试传递数据,或者只是在background.js和Content.js之间进行通信,请参见 这篇文章有一些很好的例子 { "m

我正在开发一个Chrome插件,需要帮助将数据从popup.html转发到background.js

我想将文本粘贴到弹出窗口中的输入文本框中,并能够在后台脚本中使用它,目前,它应该只追加文本,但我计划使用文本操作来自动化“数据库”输入工作。 从excel通过我的插件到某些表单

Manifest.json

Popup.html

background.js


如果您正在尝试传递数据,或者只是在background.js和Content.js之间进行通信,请参见

这篇文章有一些很好的例子

{
  "manifest_version": 2,

      "name": "LMT",
      "description": "This extension will save your life",
      "version": "1.0",

  "browser_action": {
       "default_icon": "icon.png",
       "default_popup": "popup.html",
       "default_title": "LMT"
  },
  "background": {
      "scripts": ["background.js"]

  },
    "content_scripts":[{
        "matches": ["http://*/*","https://*/*"],
        "js":["contentscript.js"]

}],
      "permissions": [
       "activeTab",
       "background" ,
       "tabs",
       "http://*/*",
       "https://*/*"
   ]
}
<!DOCTYPE html>
<html>
<head>
    <script src="contentscript.js"></script>
    <style>body{height: 100px;width: 200px;}</style>
</head>
<body>

    <p>Welcome to Upload tool</p>
    <input type="text" id="inputxt">
    <button id="start">Start</button>

</body>
</html>
(function() {

    document.addEventListener("DOMContentLoaded", function(event) { 
        var element = document.getElementById('start');

        var txtimport = document.getElementById('inputxt');
        element.addEventListener('click', function () {


                chrome.tabs.executeScript(null,{file:"background.js"});

                //alert("BOF");

        });
    });


})();
var x = document.createElement("div");
var t = document.createTextNode("This is a paragraph.");
x.appendChild(t);
x.style.width = "80%";
x.style.marginLeft = "50px";
x.style.height = "300px";
x.style.background = "#499";
x.style.color = "white";
document.body.appendChild(x);