将JavaScript回调函数转换为jQuery?

时间:2017-06-18 22:03:39

标签: jquery google-chrome-extension

我的Google扩展程序的代码如下:

window.addEventListener('DOMContentLoaded', function() {
    chrome.tabs.query({
        active: true,
        currentWindow: true
    }, function(tabs) {
        chrome.tabs.sendMessage(tabs[0].id, {
            from: 'popup',
            subject: 'Import'
        }, ShowResult);
    });
});

function ShowResult(result) {
    alert(result);
}

是否可以将此代码转换为jQuery?我不确定chrome.tabs.* ...

是什么

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

$(document).ready(function(){
    chrome.tabs.query({
        active: true,
        currentWindow: true
    }, function(tabs) {
        chrome.tabs.sendMessage(tabs[0].id, {
            from: 'popup',
            subject: 'Import'
        }, ShowResult);
    });
});

function ShowResult(result) {
    alert(result);
}