popup和content.js没有在chrome扩展中进行通信
我试图从使用chrome扩展名打开的标签中获取数据。 到目前为止,我的扩展程序可以打开一个带有正确链接的新选项卡,但是我无法获取content.js来响应单击弹出窗口中的提交按钮。 我的整个代码如下。 我真的很感激任何帮助。
popup.js
$(document).ready(function(){ function d(c){ console.log(c) } $('#rt').click(function(){ var mov = $('input:text').val() //open new link with movie title name var movUpdate = mov.replace(/ /g,'_') var link = "http://www.rottentomatoes.com/m/" + movUpdate chrome.tabs.create({"url":link,"selected":false},function(tab){ chrome.tabs.sendMessage(tab.id,{"message":"clicked_submit"}) d(tab.id) }) }) })
这是我的内容-js,它没有记录’弹出消息’
function d(c){ console.log(c) } chrome.runtime.onMessage.addListener( function(request,sender,sendResponse){ if(request.message==='clicked_submit'){ //find the rottentomato scores d('popup message') } });
popup.html
Search RT for Movie: