2011-12-14 52 views
1

我想如下調用從彈出的HTML內容的腳本功能無法正常工作

調用ContentScript.js文件功能在popu.html點擊按鈕在popup.html

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

在我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. 
}); 

但是,這並不爲我工作。請幫我...

+0

那它不起作用呢?嘗試使用[調試器中的斷點](https://code.google.com/chrome/extensions/tut_debugging.html)逐步查看代碼,然後查看哪些內容和哪些內容無效。 – abraham 2011-12-14 20:54:15

回答

1

我發現了這個問題。問題是{和}大括號在中頻條件下丟失。