How to assign a chrome tab to a variable by a given tab id in javascript? -


i tried assign tab variable; failed. here code:

var tab; chrome.tabs.get(id, function(t) {   tab = t;   console.log("tab: " + tab); // here printed result right }); console.log("(after assignment) tab: " + tab); // "undefined" 

the code simple don't know problem is...

the problem in asynchronous chrome api calls, meaning don't receive response them immediately. can rewrite code in way example:

var tab; chrome.tabs.get(id, function(t) {   tab = t;   console.log("tab: " + tab); // here printed result right    afterassignment(); });  function afterassignment() {     console.log("(after assignment) tab: " + tab); // "undefined"      //the rest of code needs use tab var } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -