0

I'm really at a loss on how do do this. I've looked over chrome's message passing api, but still unclear on how I message between a content script and popup.html (popup.js) I have a content script that's being loaded through background.js via a chrome.tabs.executeScript. I simply want to send a message from the contentscript to a div

<div id="listener"></div>

in popup.html. I have a simple if/else statement in my content script and want to send a message to the div in popup.html when the else is fired.

I'm already using .on listener from jquery which will trigger other functions based on what text is in the listener div, but I'm stuck on message passing.

oxtail
  • 33
  • 1
  • 4
  • Is the popup open at the time of activating the content script? If yes, just use the [message passing API](https://developer.chrome.com/extensions/messaging.html). If not, see http://stackoverflow.com/questions/17103903/howto-send-a-message-from-content-script-to-inactive-popup-chrome-extension – Rob W Aug 12 '13 at 13:00
  • @RobW yes the popup is open at the time of activating the content script. Initially, I did look over the message passing API but couldn't get the syntax right. The pop up just wouldn't receive the message from my content script. I'll give it another go, and check the link you shred. Cheers. – oxtail Aug 12 '13 at 15:08

1 Answers1

0

@RobW thanks for the guidance on the sendMessage. After digging through your link and this link, then this other link, I realized I had to add another listener on my popup.js

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
            if(request.pagestatus != ""){
                $(".mystatus").text(request.pagestatus);
            }
        });

Now I can send an variety of messages to my popup from any part of my extension.

Community
  • 1
  • 1
oxtail
  • 33
  • 1
  • 4