Hi! First-time poster here.
I'm relatively new to JavaScript coding, and this simple problem is giving me fits. I'm writing an extension for Google Chrome that has a page action. I can get the page action icon to appear and disappear with it's supposed to, no problem. When the page action icon is clicked, a popup should appear showing the URL of the active tab in the current window. Again, the popup appears just like it should, no problem. However, I can't get the URL of the tab to appear. Instead, the popup shows "Oops!" (the bit I put in there to indicate that something went wrong).
I think the problem lies in my
chrome.tabs.query method call. As an example, this script will work fine, placing "-2" (the current window ID) in the popup content.
Code:
var win = chrome.windows.WINDOW_ID_CURRENT;
document.getElementById("test").innerHTML=win;
This script, however, will not work. The terrible "Oops!" still appears in the popup content.
Code:
var add; // initialized here
var win = chrome.windows.WINDOW_ID_CURRENT; // to be used
var tab; // globally
// get active tab ID from current window
chrome.tabs.query({
active: true, // select active tabs
windowID: win // in current window
}, function(array_of_Tabs) {
tab = array_of_Tabs[0]; // array should have only 1 element
});
add = tab.url;
document.getElementById("test").innerHTML=add;
I've checked with the Google APIs, and I can't figure out the problem with my method call. Is there something in my syntax that I'm missing?