I need to access the tab.Id of a window that my Chrome extension has created.
Here's the code I'm using to create a window:
chrome.windows.create({
url: fullUrl,
width: w,
height: h,
type: 'normal'
}, function() {
chrome.windows.getCurrent(function(window) {
chrome.tabs.getSelected(window.id,
function (response){
var ourWindow = response.id
alert('created a window with a tab id of: ' + ourWindow);
});
});
});
And the code where I'd like to be able to access that 'ourWindow' variable we previously set:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status == "loading") {
if(开发者_如何学运维tabId == ourWindow) {
alert('Holy smokes, this is the window we created!');
}
}
});
I can't seem to access the variable, since it was created outside of the onUpdated.addListener. Any ideas?
Just move this var into global variable space:
var ourWindow = null;
...
chrome.tabs.getSelected(window.id,
function (response){
ourWindow = response.id;
});
精彩评论