zoukankan      html  css  js  c++  java
  • Chrome扩展程序 后台js与前台js数据交互

    1.后台代码:

    sendMessage

        chrome.extension.sendMessage(string extensionId, any message, function responseCallback)

        向扩展内的其它监听者发送一条消息。与chrome.extension.connect类似,但仅发送单条消息(响应回调函数可选)。 此消息发送后会触发扩展内每个页面的chrome.extension.onMessage事件。

    参数

        extensionId optional string )您想发送消息的目标扩展的ID。若忽略,默认为本函数调用者所在的扩展。
        message any )
        responseCallback optional function )
    参数
        response any )消息监听者返回的响应数据(格式是JSON)。若消息发送失败,回调函数也会被调用,响应数据为空,chrome.extension.lastError中记录错误信息描述。

    回调

        回调参数应如下例所示:

        function(any response) {...};
        response any )消息监听者返回的响应数据(格式是JSON)。若消息发送失败,回调函数也会被调用,响应数据为空,chrome.extension.lastError中记录错误信息描述。
     
     
    2.前台代码:
     

        chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
          console.log('收到消息' + request.msg);
        });

  • 相关阅读:
    读书笔记_数学之美
    在VMware上安装ubuntu——网络类型
    读书笔记_探索式测试_全局探索式测试法
    读书笔记_探索式测试_软件质量和手工测试
    关系型数据库的范式
    求最小支配集,最小点覆盖,最大独立集
    10.20testT3
    10.24testT3
    [HNOI2015]亚瑟王
    卡塔兰数
  • 原文地址:https://www.cnblogs.com/jeesezhang/p/3678603.html
Copyright © 2011-2022 走看看