2017-06-18 96 views
-4

我有我的谷歌扩展以下代码:将JavaScript回调函数转换为jQuery?

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

尝试以下操作:

$(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); 
} 
+1

它的工作!我想我试过这个,除了我把ShowResult放在jQuery中。非常感谢! –

+0

不客气,问候。 – Syden

+0

@СлавенаХаджидимитрова - 这仍然有效。 –