contentscript.js

function createIDArray()
    {
        var IDArray = []; 

        IDArray[0] = $('#u_4_0 > span > div').html();


        return IDArray;
    }

    chrome.runtime.onMessage.addListener(
      function(request, sender, sendResponse) {
        console.log("This is being received from popup.js");
        if (request.greeting == "hello")
          console.log(createIDArray());
          sendResponse({farewell: "goodbye"});
          return true;

      });

popup.js

$('#9610').click
(

    function()
    {
        chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
          chrome.tabs.sendMessage(tabs[0].id, {greeting: "This is data."}, function(response) {
            console.log(response.farewell);
          });
        });
    }
);

Not receiving any response between the two scripts. My end goal here is going to be upon clicking a button in the popup, activate a function in the content script.

两个脚本之间没有收到任何响应。我的最终目标是点击弹出窗口中的按钮,激活内容脚本中的一个功能。

popup.html

<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script src="popup.js"></script>

</head>
<body>
    <button id="9610">Copy SRT Data</button>
    <button id="1691">Paste SRT Data</button>
</body>

manifest.json

{
  "manifest_version": 2,

  "name": "Task Auto Fill",
  "description": "This extension shows a Google Image search result for the current page",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },

  "name": "My extension",
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": [
    "https://our.intern.facebook.com/",
    "tabs",
    "activeTab"

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

1 个解决方案

#1


0

  1. Please move your <script> tag in popup.html to the bottom of <body> tag. Please be aware currently you are putting them inside <head> and when $('#9610').click() is executed, the <body> is not constructed and you won't find the button at all.

    请将popup.html中的

  2. Update request.greeting == "hello" in your contentscript.js. Please keep it sync with the data you sent from popup.js

    在contentscript.js中更新request.greeting ==“hello”。请保持与您从popup.js发送的数据同步

更多相关文章

  1. 彻底解决IE8和IE9下ewebeditor上按钮无效的方法
  2. 如何在单击按钮时将桌面应用程序导航到系统中设置的默认邮件提供
  3. 浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本
  4. 像C#一样,去写Javascript----记我的脚本库RockSniper.Scripts.js
  5. 如何在选择单选按钮时显示文本字段
  6. bootstrap入门【按钮式下拉菜单,输入框组】
  7. 在AngularJS中轻松控制dom - 单击按钮,然后将焦点设置为输入元素
  8. 无法从按钮onclick事件ASP.NET 4调用Javascript函数
  9. 隐藏加载更多记录按钮ASP.net MVC Ajax Javascript

随机推荐

  1. Android序列化
  2. android开发步骤简要笔记
  3. 同步、更新、下载Android Source & SDK f
  4. Android的核心服务 2
  5. Eclipse Android project name有错误, sou
  6. android 检测网络或wifi是否开启
  7. GridView的简单使用,带有点击事件
  8. [入门]Android的应用程序框架
  9. 跨平台移动开发 Android使用JPush推送消
  10. Android 4高级编程(第3版)》