3

I am trying to call a ContentScript.js file function on click of a button in popu.html as below

In popup.html

$('#properties').live('click',function()
{
   chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) {
       alert(response.farewell);
    });
   });
});

In my contentScript.js

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.greeting == "hello")
    var pid = $('#ctlform').attr('action').split(".")[0].split("/")[2];
    var qids = [];
    $('fieldset').each(function()
    {
        var qid = $(this).prop('id').split('_')[1];
        qids.push(qid);
    });
    var ReqDat = pid+"p_p"+qids.join('SCIA');       
    sendResponse({farewell: ReqDat});
else
    sendResponse({}); // snub them.
 });

But this does not work for me.. Please help me...

Exception
  • 8,111
  • 22
  • 85
  • 136
  • What about it isn't working? Try stepping through your code using [breakpoints in the debugger](https://code.google.com/chrome/extensions/tut_debugging.html) and see what does and what doesn't work. – abraham Dec 14 '11 at 20:54
  • If I write any code in between then it is not working...For example If i write SendResponse with static text that will work.. – Exception Dec 14 '11 at 20:58
  • Does the popup stay open the whole time? – abraham Dec 14 '11 at 21:29
  • @abraham Yes..Even on clicking on the button popup is not closed.. In contentscript.js I am not using any document.ready function thinking that only one message pass allowed per event.. – Exception Dec 14 '11 at 21:31
  • I have got the problem.. I was missing { and } for if condition :-) OMG – Exception Dec 14 '11 at 21:43
  • 1
    Those bugs suck. Glad you figured it out. – abraham Dec 14 '11 at 21:49
  • @abraham Very thanks for your help on this :-) – Exception Dec 14 '11 at 21:58
  • Happy to. Don't forget to close or answer this question :) – abraham Dec 14 '11 at 22:00
  • @abraham Can you help me on this Question please. I am strucked here and waiting for help please help me on this http://stackoverflow.com/questions/8509670/how-to-read-the-clipboard-text-in-google-chrome-extension – Exception Dec 14 '11 at 22:25

1 Answers1

1

I have found the problem. The problem was { and } braces are missing in IF condition.

Exception
  • 8,111
  • 22
  • 85
  • 136