通过扩展中的内容脚本调用父页面功能

时间:2016-01-21 06:24:23

标签: javascript

我的网页如下:

    <body>
    <div class="row">                       
    <button type="button" class="btn btn-primary" id="manual-dial" onclick="dial()";>DIAL</button>
    </div>
    </body>
   /* the dial() function is written in js of parent web page */

content.js如下:

    var phone=document.getElementById("manual-dial");
    phone.addEventListener("click",dial, false);/*want to call dial function of webpage*/
   chrome.runtime.sendMessage(/*send response from dial() to background.js*/);

background.js

  chrome.runtime.onMessage.addListener(function(response,sender,sendResponse)   {
alert(response);
});

我想从扩展程序调用我的网页的dial()函数。我怎样才能做到这一点 ?

0 个答案:

没有答案